cdpierse / cdpierse/transformers-interpret

Mismatch in Predicted Labels and ignored_labels=['O'] Not Working

Open
#151 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Jupyter Notebook
Stars
1.4k
Forks
99
PR merge metrics
No merged PRs in 30d

Description

For my token classification task, the predicted labels from the explainer differ from those obtained using the pipeline. Some tokens that should have a label are instead predicted as 'O' by the explainer. Even after setting `ignored_labels=['O']`, these tokens are still included in the visualization (with only the true 'O' tokens being excluded) and continue to be displayed as 'O' in the visual.

pipeline prediction :

```
[{'end': 50,
'entity_group': 'OrderAndDelivery',
'score': 0.91371477,
'start': 4,
'word': 'colis a été marqué comme livré alors que je ne'},
{'end': 62,
'entity_group': 'OrderAndDelivery',
'score': 0.6080048,
'start': 56,
'word': 'jamais'}]
```
Explainer :

![image](https://github.com/user-attachments/assets/a1fd2150-df4a-490a-ae8e-df0037aaf154)

Has anyone else experienced this issue or found a solution?
Below is the code:
```
config = AutoConfig.from_pretrained('models/ner_model_camembert_v7')
max_length=120
model = AutoModelForTokenClassification.from_pretrained('models/ner_model_camembert_v7', config=config)
tokenizer = AutoTokenizer.from_pretrained('models/ner_model_camembert_v7', config=config, truncation=True, return_offsets_mapping=True, padding="max_length", max_length=max_length)

model.eval()

ner_explainer = TokenClassificationExplainer(
model,
tokenizer
)

sample_text = "Mon colis a été marqué comme livré alors que je ne l ai jamais reçu"

word_attributions = ner_explainer(sample_text, ignored_labels=['O'])

pipe = pipeline("token-classification", model=model, aggregation_strategy="simple", tokenizer=tokenizer)
output_model = pipe(sample_text)
pprint(output_model)

ner_explainer.visualize()

```

Contributor guide

Open the contributing guide

Research direction

Start with TokenClassificationExplainer and compare its output with the transformers token-classification pipeline shown in the issue. Trace how ignored_labels=['O'] affects attribution and visualization, using the supplied sample text to reproduce the mismatch. Done means predicted labels align with the pipeline and ignored O tokens are excluded from the visualization.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.