Views
No views yet
transformers and torch libraries installed. Install them via pip if necessary:pip install transformers torch1from transformers import AutoTokenizer, AutoModelForTokenClassification
2from transformers import pipeline
3
4# Load the tokenizer and model
5model_name = "Lokeshwaran/xlm-roberta-base-fintuned-panx-ta-hi"
6tokenizer = AutoTokenizer.from_pretrained(model_name)
7model = AutoModelForTokenClassification.from_pretrained(model_name)
8
9# Create an NER pipeline
10ner_pipeline = pipeline("ner", model=model, tokenizer=tokenizer, aggregation_strategy="simple")
11
12# Example text in Tamil and Hindi
13example_texts = [
14 "அப்துல் கலாம் சென்னை நகரத்தில் ஐஎஸ்ஆர்ஓ நிறுவனத்துக்கு சென்றார்.", # Abdul Kalam went to the ISRO organization in Chennai city.
15 "सचिन तेंदुलकर ने मुंबई में बीसीसीआई के कार्यालय का दौरा किया।", # Hindi: Sachin Tendulkar visited the BCCI office in Mumbai.
16 "മഹാത്മാ ഗാന്ധി തിരുവനന്തപുരം നഗരത്തിലെ ഐഎസ്ആർഒ ഓഫീസ് സന്ദർശിച്ചു." # Malayalam: Mahatma Gandhi visited the ISRO office in Thiruvananthapuram city.
17]
18
19# Perform Named Entity Recognition
20for text in example_texts:
21 results = ner_pipeline(text)
22 print(f"Input Text: {text}")
23 for entity in results:
24 print(f"Entity: {entity['word']}, Label: {entity['entity_group']}, Score: {entity['score']:.2f}")
25 print()5e-0524 (both training and evaluation)3AdamW with betas=(0.9, 0.999) and epsilon=1e-08Linear| Epoch | Training Loss | Validation Loss | F1 |
|---|---|---|---|
| 1.0 | 0.1886 | 0.2413 | 0.8096 |
| 2.0 | 0.1252 | 0.2415 | 0.8201 |
| 3.0 | 0.0752 | 0.2480 | 0.8347 |