Spaces:
Runtime error
Runtime error
Commit
•
1215fb7
0
Parent(s):
Duplicate from livinNector/TaNER
Browse filesCo-authored-by: Livin nector <livinNector@users.noreply.huggingface.co>
- .gitattributes +34 -0
- README.md +14 -0
- app.py +45 -0
- requirements.txt +5 -0
.gitattributes
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: TaNER
|
3 |
+
emoji: 🤖
|
4 |
+
colorFrom: green
|
5 |
+
colorTo: blue
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.15.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: mit
|
11 |
+
duplicated_from: livinNector/TaNER
|
12 |
+
---
|
13 |
+
|
14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from transformers import AutoTokenizer, AutoModelForTokenClassification
|
4 |
+
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained("ai4bharat/IndicNER")
|
6 |
+
|
7 |
+
model = AutoModelForTokenClassification.from_pretrained("ai4bharat/IndicNER")
|
8 |
+
|
9 |
+
|
10 |
+
def get_ner(sentence):
|
11 |
+
tok_sentence = tokenizer(sentence, return_tensors='pt')
|
12 |
+
|
13 |
+
with torch.no_grad():
|
14 |
+
logits = model(**tok_sentence).logits.argmax(-1)
|
15 |
+
predicted_tokens_classes = [
|
16 |
+
model.config.id2label[t.item()] for t in logits[0]]
|
17 |
+
|
18 |
+
predicted_labels = []
|
19 |
+
|
20 |
+
previous_token_id = 0
|
21 |
+
word_ids = tok_sentence.word_ids()
|
22 |
+
for word_index in range(len(word_ids)):
|
23 |
+
if word_ids[word_index] == None:
|
24 |
+
previous_token_id = word_ids[word_index]
|
25 |
+
elif word_ids[word_index] == previous_token_id:
|
26 |
+
previous_token_id = word_ids[word_index]
|
27 |
+
else:
|
28 |
+
predicted_labels.append(predicted_tokens_classes[word_index])
|
29 |
+
previous_token_id = word_ids[word_index]
|
30 |
+
|
31 |
+
ner_output = []
|
32 |
+
for index in range(len(sentence.split(' '))):
|
33 |
+
ner_output.append(
|
34 |
+
(sentence.split(' ')[index], predicted_labels[index]))
|
35 |
+
return ner_output
|
36 |
+
|
37 |
+
|
38 |
+
iface = gr.Interface(get_ner,
|
39 |
+
gr.Textbox(placeholder="Enter sentence here..."),
|
40 |
+
["highlight"], description='NER Specialized for Tamil Language.',
|
41 |
+
examples=["முதல்வர் ஸ்டாலின் பட்டமளிப்பு விழாவிற்காக சிதம்பரத்திலுள்ள அண்ணாமலைப் பல்கலைகழகத்திற்கு வருகை தந்தார்.","வல்லவராயன் வந்தியதேவனும் ஆதித்திய கரிகாலனும் கடம்பூருக்குச் சென்றனர். "], title='TaNER',
|
42 |
+
article='TaNER is a model developed for NER in Tamil Language'
|
43 |
+
)
|
44 |
+
|
45 |
+
iface.launch(enable_queue=True)
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
torch
|
3 |
+
sentencepiece==0.1.95
|
4 |
+
datasets
|
5 |
+
seqeval
|