def test_smoke_attention_charts(): """A smoke test to make sure no errors pop up while making attention charts""" model_folder = "tests/demo/models" model_path = list(pathlib.Path(model_folder).glob("*"))[0] interpreter = load_interpreter(model_folder, str(model_path.parts[-1])) text_input = "hello world this is dog" diag_data, tokens = fetch_attention_feats(interpreter, text_input) _ = make_attention_charts(diag_data, tokens)
def test_can_pick_up_entities(): model_folder = "tests/demo/models" model_path = list(pathlib.Path(model_folder).glob("*"))[0] interpreter = load_interpreter(model_folder, str(model_path.parts[-1])) blob, nlu_dict, tokens = fetch_info_from_message(interpreter=interpreter, text_input="hello python") assert blob["entities"][0]["entity"] == "proglang" assert blob["entities"][0]["value"] == "python"
def test_load_interpreter_can_load(): model_folder = "tests/demo/models" model_path = list(pathlib.Path(model_folder).glob("*"))[0] interpreter = load_interpreter(model_folder, str(model_path.parts[-1])) blob, nlu_dict, tokens = fetch_info_from_message(interpreter=interpreter, text_input="hello world") assert blob["text"] == "hello world" assert tokens == ["hello", "world"] all_intents = [ "talk_code", "bot_challenge", "mood_unhappy", "mood_great", "deny", "affirm", "goodbye", "greet", ] assert [i["name"] in all_intents for i in blob["intent_ranking"]]
def test_load_interpreter_can_load(): model_folder = "tests/demo/models" model_path = list(pathlib.Path(model_folder).glob("*"))[0] interpreter = load_interpreter(model_folder, str(model_path.parts[-1])) msg = Message("hello world") for i, element in enumerate(interpreter.pipeline): element.process(msg) nlu_dict = msg.as_dict_nlu() assert nlu_dict["text"] == "hello world" assert [t.text for t in nlu_dict["tokens"]] == ["hello", "world", "__CLS__"] all_intents = [ "talk_code", "bot_challenge", "mood_unhappy", "mood_great", "deny", "affirm", "goodbye", "greet", ] assert [i["name"] in all_intents for i in nlu_dict["intent_ranking"]]
parser = argparse.ArgumentParser(description="") parser.add_argument("--folder", help="Pass the model folder.") args = parser.parse_args() model_folder = args.folder st.markdown("# Arabic KYC NLU Model Summary") st.markdown("You can select a model on the left to interact with.") model_files = [ str(p.parts[-1]) for p in pathlib.Path(model_folder).glob("*.tar.gz") ] model_file = st.sidebar.selectbox("What model do you want to use", model_files) interpreter = load_interpreter(model_folder, model_file) text_input = st.text_input("Text Input for Model", "Hello") blob, nlu_dict, tokens = fetch_info_from_message(interpreter=interpreter, text_input=text_input) st.markdown("## Tokens and Entities") st.write( create_displacy_chart(tokens=tokens, entities=blob["entities"]), unsafe_allow_html=True, ) st.markdown("## Intents") chart_data = pd.DataFrame(blob["intent_ranking"]).sort_values("name")