Spaces:
Runtime error
Runtime error
File size: 1,171 Bytes
1b39c6e 5f36283 30efcab 5f36283 1b39c6e 4959f77 5f36283 30efcab 5f36283 30efcab e1a98e8 45bb2ea 5f36283 6395b1c 5f36283 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
import torch
import streamlit as st
from transformers import pipeline, AutoTokenizer,AutoModelForTokenClassification
tokenizer=AutoTokenizer.from_pretrained("KoichiYasuoka/bert-base-japanese-upos")
model=AutoModelForTokenClassification.from_pretrained("KoichiYasuoka/bert-base-japanese-upos")
s="国境の長いトンネルを抜けると雪国であった。"
p=[model.config.id2label[q] for q in torch.argmax(model(tokenizer.encode(s,return_tensors="pt"))["logits"],dim=2)[0].tolist()[1:-1]]
print(list(zip(s,p)))
classifier = pipeline("token-classification", model="KoichiYasuoka/bert-base-japanese-upos")
def main():
st.title("POS-tagging for Japanese texts")
with st.form("text_field"):
text = st.text_area('enter some Japanese texts:')
st.text('For example : 私はタイ人です。 = I am Thai')
st.text('For example : 私は自分の国が嫌いだ! = I hate my country!')
# clicked==True only when the button is clicked
clicked = st.form_submit_button("Submit")
if clicked:
results = classifier([text])
st.json(results)
st.success(p)
if __name__ == "__main__":
main() |