MassMin commited on
Commit
4a5c6ae
·
verified ·
1 Parent(s): 2eb8adf

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +31 -39
README.md CHANGED
@@ -117,45 +117,37 @@ The model's performance is evaluated using the F1 score for NER. The predictions
117
 
118
  [More Information Needed]
119
 
120
- ## Evaluation
121
- '''python
122
- import torch
123
-
124
- from transformers import AutoTokenizer, AutoModelForTokenClassification, pipeline
125
-
126
- import pandas as pd
127
-
128
-
129
- model_checkpoint = "MassMin/xlm-roberta-base-finetuned-panx-de" # Replace with your Hugging Face model name
130
-
131
- device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
132
-
133
-
134
- tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
135
-
136
- model = AutoModelForTokenClassification.from_pretrained(model_checkpoint).to(device)
137
-
138
-
139
- ner_pipeline = pipeline("ner", model=model, tokenizer=tokenizer, framework="pt", device=0 if torch.cuda.is_available() else -1)
140
-
141
-
142
- def tag_text_with_pipeline(text, ner_pipeline):
143
-
144
- # Use the NER pipeline to get predictions
145
- results = ner_pipeline(text)
146
-
147
- # Convert results to a DataFrame for easy viewing
148
- df = pd.DataFrame(results)
149
- df = df[['word', 'entity', 'score']]
150
- df.columns = ['Tokens', 'Tags', 'Score'] # Rename columns for clarity
151
- return df
152
-
153
-
154
- text = "Jeff Dean works at Google in California."
155
-
156
- result = tag_text_with_pipeline(text, ner_pipeline)
157
-
158
- print(result)
159
 
160
 
161
  <!-- This section describes the evaluation protocols and provides the results. -->
 
117
 
118
  [More Information Needed]
119
 
120
+
121
+ ## Evaluation
122
+
123
+ ```python
124
+ import torch
125
+ from transformers import AutoTokenizer, AutoModelForTokenClassification, pipeline
126
+ import pandas as pd
127
+
128
+ model_checkpoint = "MassMin/xlm-roberta-base-finetuned-panx-de" # Replace with your Hugging Face model name
129
+
130
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
131
+
132
+ tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
133
+ model = AutoModelForTokenClassification.from_pretrained(model_checkpoint).to(device)
134
+
135
+ ner_pipeline = pipeline("ner", model=model, tokenizer=tokenizer, framework="pt", device=0 if torch.cuda.is_available() else -1)
136
+
137
+ def tag_text_with_pipeline(text, ner_pipeline):
138
+ # Use the NER pipeline to get predictions
139
+ results = ner_pipeline(text)
140
+
141
+ # Convert results to a DataFrame for easy viewing
142
+ df = pd.DataFrame(results)
143
+ df = df[['word', 'entity', 'score']]
144
+ df.columns = ['Tokens', 'Tags', 'Score'] # Rename columns for clarity
145
+ return df
146
+
147
+ text = "Jeff Dean works at Google in California."
148
+ result = tag_text_with_pipeline(text, ner_pipeline)
149
+ print(result)
150
+
 
 
 
 
 
 
 
 
151
 
152
 
153
  <!-- This section describes the evaluation protocols and provides the results. -->