Spaces:
Runtime error
Runtime error
Commit
•
45a9fa0
0
Parent(s):
Duplicate from merve/ner-active-learning
Browse filesCo-authored-by: Merve Noyan <merve@users.noreply.huggingface.co>
- .gitattributes +34 -0
- README.md +14 -0
- app.py +76 -0
- requirements.txt +3 -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: NER Active Learning
|
3 |
+
emoji: 📖
|
4 |
+
colorFrom: yellow
|
5 |
+
colorTo: green
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.18.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: apache-2.0
|
11 |
+
duplicated_from: merve/ner-active-learning
|
12 |
+
---
|
13 |
+
|
14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import gradio as gr
|
3 |
+
from gradio import FlaggingCallback
|
4 |
+
from gradio.components import IOComponent
|
5 |
+
|
6 |
+
from transformers import pipeline
|
7 |
+
|
8 |
+
from typing import List, Optional, Any
|
9 |
+
|
10 |
+
import argilla as rg
|
11 |
+
|
12 |
+
import os
|
13 |
+
|
14 |
+
|
15 |
+
|
16 |
+
nlp = pipeline("ner", model="deprem-ml/deprem-ner")
|
17 |
+
|
18 |
+
examples = [
|
19 |
+
["Lütfen yardım Akevler mahallesi Rüzgar sokak Tuncay apartmanı zemin kat Antakya akrabalarım göçük altında #hatay #Afad"]
|
20 |
+
]
|
21 |
+
|
22 |
+
def create_record(input_text):
|
23 |
+
# Making the prediction
|
24 |
+
predictions = nlp(input_text, aggregation_strategy="first")
|
25 |
+
|
26 |
+
# Creating the predicted entities as a list of tuples (entity, start_char, end_char, score)
|
27 |
+
prediction = [(pred["entity_group"], pred["start"], pred["end"], pred["score"]) for pred in predictions]
|
28 |
+
|
29 |
+
# Create word tokens
|
30 |
+
batch_encoding = nlp.tokenizer(input_text)
|
31 |
+
word_ids = sorted(set(batch_encoding.word_ids()) - {None})
|
32 |
+
words = []
|
33 |
+
for word_id in word_ids:
|
34 |
+
char_span = batch_encoding.word_to_chars(word_id)
|
35 |
+
words.append(input_text[char_span.start:char_span.end])
|
36 |
+
|
37 |
+
# Building a TokenClassificationRecord
|
38 |
+
record = rg.TokenClassificationRecord(
|
39 |
+
text=input_text,
|
40 |
+
tokens=words,
|
41 |
+
prediction=prediction,
|
42 |
+
prediction_agent="deprem-ml/deprem-ner",
|
43 |
+
)
|
44 |
+
print(record)
|
45 |
+
return record
|
46 |
+
|
47 |
+
class ArgillaLogger(FlaggingCallback):
|
48 |
+
def __init__(self, api_url, api_key, dataset_name):
|
49 |
+
rg.init(api_url=api_url, api_key=api_key)
|
50 |
+
self.dataset_name = dataset_name
|
51 |
+
def setup(self, components: List[IOComponent], flagging_dir: str):
|
52 |
+
pass
|
53 |
+
def flag(
|
54 |
+
self,
|
55 |
+
flag_data: List[Any],
|
56 |
+
flag_option: Optional[str] = None,
|
57 |
+
flag_index: Optional[int] = None,
|
58 |
+
username: Optional[str] = None,
|
59 |
+
) -> int:
|
60 |
+
text = flag_data[0]
|
61 |
+
inference = flag_data[1]
|
62 |
+
rg.log(name=self.dataset_name, records=create_record(text))
|
63 |
+
|
64 |
+
|
65 |
+
|
66 |
+
gr.Interface.load(
|
67 |
+
"models/deprem-ml/deprem-ner",
|
68 |
+
examples=examples,
|
69 |
+
allow_flagging="manual",
|
70 |
+
flagging_callback=ArgillaLogger(
|
71 |
+
api_url="https://merve-argilla.hf.space",
|
72 |
+
api_key=os.getenv("TEAM_API_KEY"),
|
73 |
+
dataset_name="ner-flags"
|
74 |
+
),
|
75 |
+
flagging_options=["Correct", "Incorrect", "Ambiguous"]
|
76 |
+
).launch()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
torch
|
3 |
+
argilla
|