research14 commited on
Commit
58e0da5
1 Parent(s): 8b150b6

testing LFTK with a sentence in code

Browse files
Files changed (1) hide show
  1. app.py +7 -11
app.py CHANGED
@@ -14,24 +14,23 @@ vicuna_model = AutoModelForCausalLM.from_pretrained("lmsys/vicuna-7b-v1.3")
14
  llama_tokenizer = AutoTokenizer.from_pretrained("daryl149/llama-2-7b-chat-hf")
15
  llama_model = AutoModelForCausalLM.from_pretrained("daryl149/llama-2-7b-chat-hf")
16
 
17
- def linguistic_features(message):
18
  # Load a trained spaCy pipeline
19
  nlp = spacy.load("en_core_web_sm")
20
 
21
  # Create a spaCy doc object
22
- doc = nlp(message)
23
 
24
  # Initiate LFTK extractor by passing in the doc
25
- LFTK_extractor = lftk.Extractor(docs=doc)
26
 
27
  # Customize LFTK extractor (optional)
28
- LFTK_extractor.customize(stop_words=True, punctuations=False, round_decimal=3)
29
 
30
  # Use LFTK to dynamically extract handcrafted linguistic features
31
- features_to_extract = lftk.search_features(family="wordsent", language="general", return_format="list_key")
32
- extracted_features = LFTK_extractor.extract(features=features_to_extract)
33
 
34
- print('Linguistic Features:', extracted_features)
35
 
36
  return extracted_features
37
 
@@ -263,10 +262,7 @@ def interface():
263
 
264
  ling_ents_btn.click(fn=update_textbox, inputs=ling_ents_prompt, outputs=user_prompt_1, api_name="ling_ents_btn")
265
 
266
- ling_ents_btn.click(lambda _,
267
- message=ling_ents_prompt: linguistic_features_textbox.update(linguistic_features(ling_ents_prompt.value)),
268
- inputs=[ling_ents_prompt],
269
- outputs=[linguistic_features_textbox])
270
 
271
  # Event Handler for GPT 3.5 Chatbot
272
  ling_ents_btn.click(gpt_respond, inputs=[have_key2, linguistic_entities, ling_ents_prompt, gpt_ling_ents_chatbot],
 
14
  llama_tokenizer = AutoTokenizer.from_pretrained("daryl149/llama-2-7b-chat-hf")
15
  llama_model = AutoModelForCausalLM.from_pretrained("daryl149/llama-2-7b-chat-hf")
16
 
17
+ def linguistic_features_fn(message):
18
  # Load a trained spaCy pipeline
19
  nlp = spacy.load("en_core_web_sm")
20
 
21
  # Create a spaCy doc object
22
+ doc = nlp("I love research but my professor is strange.")
23
 
24
  # Initiate LFTK extractor by passing in the doc
25
+ LFTK = lftk.Extractor(docs=doc)
26
 
27
  # Customize LFTK extractor (optional)
28
+ LFTK.customize(stop_words=True, punctuations=False, round_decimal=3)
29
 
30
  # Use LFTK to dynamically extract handcrafted linguistic features
31
+ extracted_features = LFTK.extract(features = ["a_word_ps", "a_kup_pw", "n_noun"])
 
32
 
33
+ print(extracted_features)
34
 
35
  return extracted_features
36
 
 
262
 
263
  ling_ents_btn.click(fn=update_textbox, inputs=ling_ents_prompt, outputs=user_prompt_1, api_name="ling_ents_btn")
264
 
265
+ ling_ents_btn.click(linguistic_features_fn, inputs=[ling_ents_prompt], outputs=[linguistic_features_textbox])
 
 
 
266
 
267
  # Event Handler for GPT 3.5 Chatbot
268
  ling_ents_btn.click(gpt_respond, inputs=[have_key2, linguistic_entities, ling_ents_prompt, gpt_ling_ents_chatbot],