Spaces:
Runtime error
Runtime error
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() |