🔬
The Fair-ly Project
  • Welcome to RumorMill
    • Recent Papers Timeline
  • Fair-ly Toolkit
    • Chrome Extension
    • Python Package
      • TextAnalyzer Pipeline
      • MultimodalAnalyzer Pipeline
    • Hosted APIs
  • Research
    • Sequence Classification
      • Binary
      • Multi-class
    • Named-Entity Recognition
      • Token Classification
    • Multimodal
      • Image + Text Pair Classification
    • Datasets
      • News Media Bias Plus (2024)
      • BEADs Dataset (2024)
      • GUS Dataset (2024)
      • BABE Dataset (2022)
  • Learn
    • Blog Posts
      • Training a model for multi-label NER
      • Binary Classification w/ BERT
  • Join the Project
    • To Do List
    • Discord Server
    • GitHub Repo
  • Misc
    • Privacy Policy
Powered by GitBook
On this page
  • 1. Import
  • 2. Initialize the Module
  • 3. Run Bias Analysis
  • 4. Example Output
Edit on GitHub
  1. Fair-ly Toolkit
  2. Python Package

TextAnalyzer Pipeline

Python module for using NLP bias analysis models.

1. Import

# pip install the-fairly-project
from fairly import TextAnalyzer

2. Initialize the Module

text_pipeline = TextAnalyzer(
    bias="ternary", # defaults to None
    classes=True, # defaults to False
    top_k_classes=3, # defaults to 3
    ner="gus" 
    )

Customize your pipeline

Args
Options

bias

  • None: Default (no bias sequence classification).

When set to ternary this adds two fields to the "text" dictionary in the return dictionary: label (as shown above) and score (0-1).

classes

Classify the types of bias a sentence contains:

  • False: Default (no bias aspects classification).

When set to True, this adds one field to the "text" dictionary in the return dictionary: aspects(which contains top_k_classes in [CLASS]: [SCORE] format).

top_k_classes

Number of classes returned in the aspects dict.

  • Int: 1 to 11 (defaults to 3).

Only relevant when classes is set to True.

ner

  • None: Default (no token classification)

When in use, it appends a new "ner" dictionary to the return dictionary.

3. Run Bias Analysis

result = text_pipeline.analyze("Data scientists are so smart")

4. Example Output

{
'text': {
    'text': 'Tall people are so clumsy.', 
    'label': 'Slightly Biased', 
    'score': 0.6829080581665039, 
    'aspects': {
      'physical': 0.9650779366493225, 
      'gender': 0.024978743866086006, 
      'socioeconomic': 0.023334791883826256
    }
}, 
'ner': [
    {'token': 'tall', 'labels': ['B-STEREO', 'B-GEN', 'B-UNFAIR']}, 
    {'token': 'people', 'labels': ['I-STEREO', 'I-GEN', 'I-UNFAIR']}, 
    {'token': 'are', 'labels': ['I-STEREO']}, 
    {'token': 'so', 'labels': ['I-STEREO']}, 
    {'token': 'clumsy', 'labels': ['I-STEREO', 'B-UNFAIR', 'I-UNFAIR']},
    {'token': '.', 'labels': ['I-STEREO', 'I-UNFAIR']}
    ]
}
PreviousPython PackageNextMultimodalAnalyzer Pipeline

Last updated 7 months ago

Classify bias at the sentence level ():

"ternary": Uses (e.g. Neutral, Slightly Biased, Highly Biased). .

"binary": Not implemented yet. (e.g. Fair, Biased) .

True: Uses (11 classes). .

Run on the text sequence.

"gus": Uses (e.g. GEN, UNFAIR, STEREO). .

sequence classification
Unbias
More info
More info
fairlyAspects
More info
named-entity recognition
GUS-Net
More in
fo