Spaces:
Runtime error
Runtime error
Add application file
Browse files
app.py
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Turkish POS Tagging with XLM-RoBERTa Model
|
2 |
+
|
3 |
+
from transformers import pipeline, AutoModelForTokenClassification, AutoTokenizer
|
4 |
+
import sentencepiece
|
5 |
+
import streamlit as st
|
6 |
+
import pandas as pd
|
7 |
+
import spacy
|
8 |
+
|
9 |
+
text_1 = "Mustafa Kemal Atatürk 1881 yılında Selanik'te doğdu."
|
10 |
+
|
11 |
+
text_2 = """Dünya çapında 40 milyondan fazla insana bulaşan ve 1.1 milyondan fazla insanın ölümüne sebep olan \
|
12 |
+
corona virüsüne karşı Pfizer ile BioNTech'in geliştirdiği aşının ilk görüntüleri ortaya çıktı. Aşının fabrikadaki \
|
13 |
+
ilk görüntülerini değerlendiren Pfizer'ın Birleşik Krallık CEO'su, "Üretim bandında aşıyı görmek beni neşelendirdi" \
|
14 |
+
dedi. ABD merkezli çokuluslu ilaç şirketi Pfizer ile Türk bilim insanlarının kurduğu BioNTech’in geliştirdiği corona \
|
15 |
+
virüsü aşısında sona gelindi. Pfizer, paylaştığı video ile bütün dünyayı heyecanlandıran gelişmeyi duyurdu. Şirket, \
|
16 |
+
Belçika’daki Puurs’ta geliştirilen Covid-19 aşılarının seri üretim bandındaki üretim aşamasını uluslararası kamuoyu \
|
17 |
+
ile paylaştı. Almanya’nın Mainz kentinde Türk profesör Uğur Şahin ile eşi Özlem Türeci’nin kurduğu ve yönettiği \
|
18 |
+
biyoteknoloji şirketi BioNTech ile aşı sürecini sürdüren Pfizer’ın küçük şişelerde binlerce corona virüsü aşısı \
|
19 |
+
üretmeye başladığı belirtildi. Pfizer, aşının güvenli ve etkili olduğunun klinik olarak da kanıtlanması ve resmi \
|
20 |
+
mercilerden de onay alınması durumunda üretilen aşının dağıtılacağını duyurdu."""
|
21 |
+
|
22 |
+
st.title("Demo for Turkish POS Tagging with XLM-RoBERTa")
|
23 |
+
st.sidebar.write("Model : XLM-RoBERTa base Universal Dependencies v2.8 POS tagging: Turkish")
|
24 |
+
st.sidebar.write("For details of model: 'https://huggingface.co/wietsedv/xlm-roberta-base-ft-udpos28-tr/")
|
25 |
+
# st.sidebar.write("Please refer 'https://huggingface.co/transformers/_modules/transformers/pipelines/token_classification.html' for entity grouping with aggregation_strategy parameter.")
|
26 |
+
|
27 |
+
model_checkpoint = "wietsedv/xlm-roberta-base-ft-udpos28-tr"
|
28 |
+
aggregation = "simple"
|
29 |
+
|
30 |
+
st.subheader("Select Text")
|
31 |
+
context_1 = st.text_area("Text #1", text_1, height=128)
|
32 |
+
context_2 = st.text_area("Text #2", text_2, height=128)
|
33 |
+
context_3 = st.text_area("New Text", value="", height=128)
|
34 |
+
|
35 |
+
context = st.radio("Select Text", ("Text #1", "Text #2", "New Text"))
|
36 |
+
|
37 |
+
if context == "Text #1":
|
38 |
+
input_text = context_1
|
39 |
+
elif context == "Text #2":
|
40 |
+
input_text = context_2
|
41 |
+
elif context == "New Text":
|
42 |
+
input_text = context_3
|
43 |
+
|
44 |
+
@st.cache(allow_output_mutation=True)
|
45 |
+
def setModel(model_checkpoint, aggregation):
|
46 |
+
model = AutoModelForTokenClassification.from_pretrained(model_checkpoint)
|
47 |
+
tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
|
48 |
+
return pipeline('token-classification', model=model, tokenizer=tokenizer, aggregation_strategy=aggregation)
|
49 |
+
|
50 |
+
Run_Button = st.button("Run", key=None)
|
51 |
+
if Run_Button == True:
|
52 |
+
|
53 |
+
ner_pipeline = setModel(model_checkpoint, aggregation)
|
54 |
+
output = ner_pipeline(input_text)
|
55 |
+
|
56 |
+
df = pd.DataFrame.from_dict(output)
|
57 |
+
|
58 |
+
if aggregation != "none":
|
59 |
+
df.rename(index=str,columns={'entity_group':'POS Tag'},inplace=True)
|
60 |
+
else:
|
61 |
+
df.rename(index=str,columns={'entity_group':'POS Tag'},inplace=True)
|
62 |
+
|
63 |
+
cols_to_keep = ['word','POS Tag','score','start','end']
|
64 |
+
df_final = df[cols_to_keep]
|
65 |
+
|
66 |
+
st.subheader("POS Tags")
|
67 |
+
st.dataframe(df_final)
|