from transformers import pipeline, AutoModelForTokenClassification, AutoTokenizer, DebertaV2Tokenizer, DebertaV2Model import sentencepiece import streamlit as st import pandas as pd import spacy example_list = [ "The primary outcome was overall survival (OS).", "Overall survival was not significantly different between the groups (hazard ratio [HR], 0.87; 95% CI, 0.66-1.16; P = .34).", "Afatinib-an oral irreversible ErbB family blocker-improves progression-free survival compared with pemetrexed and cisplatin for first-line treatment of patients with EGFR mutation-positive advanced non-small-cell lung cancer (NSCLC)." ] st.set_page_config(layout="wide") st.title("Demo for EIC NER") model_list = ['akdeniz27/bert-base-turkish-cased-ner', 'akdeniz27/convbert-base-turkish-cased-ner', 'akdeniz27/xlm-roberta-base-turkish-ner', 'xlm-roberta-large-finetuned-conll03-english'] st.sidebar.header("Select NER Model") model_checkpoint = st.sidebar.radio("", model_list) st.sidebar.write("For details of models: 'https://huggingface.co/akdeniz27/") st.sidebar.write("") xlm_agg_strategy_info = "'aggregation_strategy' can be selected as 'simple' or 'none' for 'xlm-roberta' because of the RoBERTa model's tokenization approach." st.sidebar.header("Select Aggregation Strategy Type") if model_checkpoint == "akdeniz27/xlm-roberta-base-turkish-ner": aggregation = st.sidebar.radio("", ('simple', 'none')) st.sidebar.write(xlm_agg_strategy_info) elif model_checkpoint == "xlm-roberta-large-finetuned-conll03-english": aggregation = st.sidebar.radio("", ('simple', 'none')) st.sidebar.write(xlm_agg_strategy_info) st.sidebar.write("") st.sidebar.write("This English NER model is included just to show the zero-shot transfer learning capability of XLM-Roberta.") else: aggregation = st.sidebar.radio("", ('first', 'simple', 'average', 'max', 'none')) st.sidebar.write("Please refer 'https://huggingface.co/transformers/_modules/transformers/pipelines/token_classification.html' for entity grouping with aggregation_strategy parameter.") st.subheader("Select Text Input Method") input_method = st.radio("", ('Select from Examples', 'Write or Paste New Text')) if input_method == 'Select from Examples': selected_text = st.selectbox('Select Text from List', example_list, index=0, key=1) st.subheader("Text to Run") input_text = st.text_area("Selected Text", selected_text, height=128, max_chars=None, key=2) elif input_method == "Write or Paste New Text": st.subheader("Text to Run") input_text = st.text_area('Write or Paste Text Below', value="", height=128, max_chars=None, key=2) @st.cache(allow_output_mutation=True) def setModel(model_checkpoint, aggregation): model = AutoModelForTokenClassification.from_pretrained(model_checkpoint) tokenizer = AutoTokenizer.from_pretrained(model_checkpoint) return pipeline('ner', model=model, tokenizer=tokenizer, aggregation_strategy=aggregation) @st.cache(allow_output_mutation=True) def get_html(html: str): WRAPPER = """