MartinoMensio commited on
Commit
eb49a75
1 Parent(s): 03a962e

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +90 -0
README.md ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: es
3
+ license: mit
4
+
5
+ widget:
6
+ - text: "y porqué es lo que hay que hacer con los menas y con los adultos también!!!! NO a los inmigrantes ilegales!!!!"
7
+ ---
8
+
9
+ ### Description
10
+ This model is a fine-tuned version of [BETO (spanish bert)](https://huggingface.co/dccuchile/bert-base-spanish-wwm-uncased) that has been trained on the *Datathon Against Racism* dataset (2022)
11
+
12
+ We performed several experiments that will be described in the upcoming paper "Estimating Ground Truth in a Low-labelled Data Regime:A Study of Racism Detection in Spanish" (NEATClasS 2022)
13
+ We applied 6 different methods ground-truth estimations, and for each one we performed 4 epochs of fine-tuning. The result is made of 24 models:
14
+
15
+ | method | epoch 1 | epoch 3 | epoch 3 | epoch 4 |
16
+ |--- |--- |--- |--- |--- |
17
+ | raw-label | [raw-label-epoch-1](https://huggingface.co/MartinoMensio/racism-models-raw-label-epoch-1) | [raw-label-epoch-2](https://huggingface.co/MartinoMensio/racism-models-raw-label-epoch-2) | [raw-label-epoch-3](https://huggingface.co/MartinoMensio/racism-models-raw-label-epoch-3) | [raw-label-epoch-4](https://huggingface.co/MartinoMensio/racism-models-raw-label-epoch-4) |
18
+ | m-vote-strict | [m-vote-strict-epoch-1](https://huggingface.co/MartinoMensio/racism-models-m-vote-strict-epoch-1) | [m-vote-strict-epoch-2](https://huggingface.co/MartinoMensio/racism-models-m-vote-strict-epoch-2) | [m-vote-strict-epoch-3](https://huggingface.co/MartinoMensio/racism-models-m-vote-strict-epoch-3) | [m-vote-strict-epoch-4](https://huggingface.co/MartinoMensio/racism-models-m-vote-strict-epoch-4) |
19
+ | m-vote-nonstrict | [m-vote-nonstrict-epoch-1](https://huggingface.co/MartinoMensio/racism-models-m-vote-nonstrict-epoch-1) | [m-vote-nonstrict-epoch-2](https://huggingface.co/MartinoMensio/racism-models-m-vote-nonstrict-epoch-2) | [m-vote-nonstrict-epoch-3](https://huggingface.co/MartinoMensio/racism-models-m-vote-nonstrict-epoch-3) | [m-vote-nonstrict-epoch-4](https://huggingface.co/MartinoMensio/racism-models-m-vote-nonstrict-epoch-4) |
20
+ | regression-w-m-vote | [regression-w-m-vote-epoch-1](https://huggingface.co/MartinoMensio/racism-models-regression-w-m-vote-epoch-1) | [regression-w-m-vote-epoch-2](https://huggingface.co/MartinoMensio/racism-models-regression-w-m-vote-epoch-2) | [regression-w-m-vote-epoch-3](https://huggingface.co/MartinoMensio/racism-models-regression-w-m-vote-epoch-3) | [regression-w-m-vote-epoch-4](https://huggingface.co/MartinoMensio/racism-models-regression-w-m-vote-epoch-4) |
21
+ | w-m-vote-strict | [w-m-vote-strict-epoch-1](https://huggingface.co/MartinoMensio/racism-models-w-m-vote-strict-epoch-1) | [w-m-vote-strict-epoch-2](https://huggingface.co/MartinoMensio/racism-models-w-m-vote-strict-epoch-2) | [w-m-vote-strict-epoch-3](https://huggingface.co/MartinoMensio/racism-models-w-m-vote-strict-epoch-3) | [w-m-vote-strict-epoch-4](https://huggingface.co/MartinoMensio/racism-models-w-m-vote-strict-epoch-4) |
22
+ | w-m-vote-nonstrict | [w-m-vote-nonstrict-epoch-1](https://huggingface.co/MartinoMensio/racism-models-w-m-vote-nonstrict-epoch-1) | [w-m-vote-nonstrict-epoch-2](https://huggingface.co/MartinoMensio/racism-models-w-m-vote-nonstrict-epoch-2) | [w-m-vote-nonstrict-epoch-3](https://huggingface.co/MartinoMensio/racism-models-w-m-vote-nonstrict-epoch-3) | [w-m-vote-nonstrict-epoch-4](https://huggingface.co/MartinoMensio/racism-models-w-m-vote-nonstrict-epoch-4) |
23
+
24
+
25
+ This model is `regression-w-m-vote-epoch-2`
26
+
27
+ ### Usage
28
+
29
+ ```python
30
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
31
+ from transformers.pipelines import TextClassificationPipeline
32
+
33
+ class TextRegressionPipeline(TextClassificationPipeline):
34
+ """
35
+ Class based on the TextClassificationPipeline from transformers.
36
+ The difference is that instead of being based on a classifier, it is based on a regressor.
37
+ You can specify the regression threshold when you call the pipeline or when you instantiate the pipeline.
38
+ """
39
+ def __init__(self, **kwargs):
40
+ """
41
+ Builds a new Pipeline based on regression.
42
+ regression_threshold: Optional(float). If None, the pipeline will simply output the score. If set to a specific value, the output will be both the score and the label.
43
+ """
44
+ self.regression_threshold = kwargs.pop("regression_threshold", None)
45
+ super().__init__(**kwargs)
46
+ def __call__(self, *args, **kwargs):
47
+ """
48
+ You can also specify the regression threshold when you call the pipeline.
49
+ regression_threshold: Optional(float). If None, the pipeline will simply output the score. If set to a specific value, the output will be both the score and the label.
50
+ """
51
+ self.regression_threshold_call = kwargs.pop("regression_threshold", None)
52
+ result = super().__call__(*args, **kwargs)
53
+ return result
54
+ def postprocess(self, model_outputs, function_to_apply=None, return_all_scores=False):
55
+ outputs = model_outputs["logits"][0]
56
+ outputs = outputs.numpy()
57
+ scores = outputs
58
+ score = scores[0]
59
+ regression_threshold = self.regression_threshold
60
+ # override the specific threshold if it is specified in the call
61
+ if self.regression_threshold_call:
62
+ regression_threshold = self.regression_threshold_call
63
+ if regression_threshold:
64
+ return {"label": 'racist' if score > regression_threshold else 'non-racist', "score": score}
65
+ else:
66
+ return {"score": score}
67
+
68
+
69
+
70
+ model_name = 'regression-w-m-vote-epoch-2'
71
+ tokenizer = AutoTokenizer.from_pretrained("dccuchile/bert-base-spanish-wwm-uncased")
72
+ full_model_path = f'MartinoMensio/racism-models-{model_name}'
73
+ model = AutoModelForSequenceClassification.from_pretrained(full_model_path)
74
+
75
+ pipe = TextRegressionPipeline(model=model, tokenizer=tokenizer)
76
+
77
+ texts = [
78
+ 'y porqué es lo que hay que hacer con los menas y con los adultos también!!!! NO a los inmigrantes ilegales!!!!',
79
+ 'Es que los judíos controlan el mundo'
80
+ ]
81
+ # just get the score of regression
82
+ print(pipe(texts))
83
+ # [{'score': 0.8367272}, {'score': 0.4402479}]
84
+
85
+ # or also specify a threshold to cut racist/non-racist
86
+ print(pipe(texts, regression_threshold=0.9))
87
+ # [{'label': 'non-racist', 'score': 0.8367272}, {'label': 'non-racist', 'score': 0.4402479}]
88
+ ```
89
+
90
+ For more details, see https://github.com/preyero/neatclass22