Binoculars Documentation

repository·main·Indexed 19 days ago

https://github.com/ahans30/binoculars

A zero-shot, domain-agnostic method for detecting AI-generated text by leveraging the overlap in pretraining datasets of causal language models. Features the Binoculars class with compute_score and predict methods, a Gradio-based interactive demo, and default support for Falcon-7B and Falcon-7B-Instruct models.

Tokens
773
Snippets
4
Records
5
Agent score
14%

What's inside Binoculars

  1. Install Binoculars

    main

    To install Binoculars, clone the repository and install the package in editable mode using pip. The implementation was developed and tested with Python 3.9.

    $ git clone https://github.com/ahans30/Binoculars.git
    $ cd Binoculars
    $ pip install -e .
  2. Binoculars limitations and usage warnings

    main

    Limitations

    • Language Proficiency: Binoculars is more proficient in detecting English language text compared to other languages.
    • Accuracy: Like all AI detectors, it is not perfect and has failure modes.

    Warnings

    • This implementation is for academic purposes only and is not a consumer product.
    • Human Supervision: Do not use Binoculars (or any detector) without human supervision.
  3. Use the Binoculars API to detect AI-generated text

    main

    You can use the Binoculars class to compute a detection score or get a direct prediction for a string or a list of strings.

    By default, the implementation uses a fixed global threshold based on Falcon-7B and Falcon-7B-Instruct models. If you need to use different scoring models, you can pass them as an argument when initializing the Binoculars class.

    Methods:

    • compute_score(text): Returns a numerical score indicating the likelihood of the text being AI-generated.
    • predict(text): Returns a string label (e.g., 'Most likely AI-Generated') based on the internal threshold.

    Both methods support passing a single str or a list of str for batch processing.

    from binoculars import Binoculars
    
    bino = Binoculars()
    
    sample_string = "'Your text here'"
    
    # Get the numerical score
    print(bino.compute_score(sample_string))
    
    # Get the classification label
    print(bino.predict(sample_string))
  4. Use the Binoculars class for LLM-generated text detection

    main

    The Binoculars class provides methods to detect whether a given string was likely generated by a Large Language Model (LLM). You can obtain a continuous probability score or a discrete classification label.

    • compute_score(text: str): Returns a numerical score representing the likelihood of the text being AI-generated.
    • predict(text: str): Returns a string label, such as 'Most likely AI-Generated', based on the computed score.
    from binoculars import Binoculars
    
    bino = Binoculars()
    sample_string = "Your text to analyze here"
    
    # Get the numerical score
    score = bino.compute_score(sample_string)
    print(score)
    
    # Get the classification label
    label = bino.predict(sample_string)
    print(label)