Nathan Butters commited on
Commit
9d6f821
1 Parent(s): 3318d47
Files changed (2) hide show
  1. .ipynb_checkpoints/app-checkpoint.py +10 -9
  2. app.py +10 -9
.ipynb_checkpoints/app-checkpoint.py CHANGED
@@ -3,6 +3,14 @@ import pandas as pd, spacy, nltk, numpy as np, re, os
3
  from spacy.matcher import Matcher
4
  from nltk.corpus import wordnet
5
 
 
 
 
 
 
 
 
 
6
  #Import the libraries to support the model and predictions.
7
  from transformers import AutoTokenizer, AutoModelForSequenceClassification, TextClassificationPipeline
8
  import lime
@@ -27,17 +35,10 @@ def set_up_explainer():
27
 
28
  @st.experimental_singleton
29
  def prepare_model():
30
- #Attempting to fix the issue with spacy model in a more intuitive way.
31
- try:
32
- nlp = spacy.load("en_core_web_lg")
33
- except:
34
- script = "python -m spacy download en_core_web_lg"
35
- os.system("bash -c '%s'" % script)
36
- nlp = spacy.load("en_core_web_lg")
37
  tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english")
38
  model = AutoModelForSequenceClassification.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english")
39
  pipe = TextClassificationPipeline(model=model, tokenizer=tokenizer, return_all_scores=True)
40
- return tokenizer, model, pipe, nlp
41
 
42
  @st.experimental_singleton
43
  def prepare_lists():
@@ -85,7 +86,7 @@ st.subheader(f'Current Layout: {layout}')
85
  text = st.text_input('Provide a sentence you want to evaluate.', placeholder = "I like you. I love you.", key="input")
86
 
87
  #Prepare the model, data, and Lime. Set starting variables.
88
- tokenizer, model, pipe, nlp = prepare_model()
89
  countries, professions, word_lists = prepare_lists()
90
  explainer = set_up_explainer()
91
  text2 = ""
 
3
  from spacy.matcher import Matcher
4
  from nltk.corpus import wordnet
5
 
6
+ #Attempting to fix the issue with spacy model in a more intuitive way.
7
+ try:
8
+ nlp = spacy.load("en_core_web_lg")
9
+ except:
10
+ script = "python -m spacy download en_core_web_lg"
11
+ os.system("bash -c '%s'" % script)
12
+ nlp = spacy.load("en_core_web_lg")
13
+
14
  #Import the libraries to support the model and predictions.
15
  from transformers import AutoTokenizer, AutoModelForSequenceClassification, TextClassificationPipeline
16
  import lime
 
35
 
36
  @st.experimental_singleton
37
  def prepare_model():
 
 
 
 
 
 
 
38
  tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english")
39
  model = AutoModelForSequenceClassification.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english")
40
  pipe = TextClassificationPipeline(model=model, tokenizer=tokenizer, return_all_scores=True)
41
+ return tokenizer, model, pipe
42
 
43
  @st.experimental_singleton
44
  def prepare_lists():
 
86
  text = st.text_input('Provide a sentence you want to evaluate.', placeholder = "I like you. I love you.", key="input")
87
 
88
  #Prepare the model, data, and Lime. Set starting variables.
89
+ tokenizer, model, pipe = prepare_model()
90
  countries, professions, word_lists = prepare_lists()
91
  explainer = set_up_explainer()
92
  text2 = ""
app.py CHANGED
@@ -3,6 +3,14 @@ import pandas as pd, spacy, nltk, numpy as np, re, os
3
  from spacy.matcher import Matcher
4
  from nltk.corpus import wordnet
5
 
 
 
 
 
 
 
 
 
6
  #Import the libraries to support the model and predictions.
7
  from transformers import AutoTokenizer, AutoModelForSequenceClassification, TextClassificationPipeline
8
  import lime
@@ -27,17 +35,10 @@ def set_up_explainer():
27
 
28
  @st.experimental_singleton
29
  def prepare_model():
30
- #Attempting to fix the issue with spacy model in a more intuitive way.
31
- try:
32
- nlp = spacy.load("en_core_web_lg")
33
- except:
34
- script = "python -m spacy download en_core_web_lg"
35
- os.system("bash -c '%s'" % script)
36
- nlp = spacy.load("en_core_web_lg")
37
  tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english")
38
  model = AutoModelForSequenceClassification.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english")
39
  pipe = TextClassificationPipeline(model=model, tokenizer=tokenizer, return_all_scores=True)
40
- return tokenizer, model, pipe, nlp
41
 
42
  @st.experimental_singleton
43
  def prepare_lists():
@@ -85,7 +86,7 @@ st.subheader(f'Current Layout: {layout}')
85
  text = st.text_input('Provide a sentence you want to evaluate.', placeholder = "I like you. I love you.", key="input")
86
 
87
  #Prepare the model, data, and Lime. Set starting variables.
88
- tokenizer, model, pipe, nlp = prepare_model()
89
  countries, professions, word_lists = prepare_lists()
90
  explainer = set_up_explainer()
91
  text2 = ""
 
3
  from spacy.matcher import Matcher
4
  from nltk.corpus import wordnet
5
 
6
+ #Attempting to fix the issue with spacy model in a more intuitive way.
7
+ try:
8
+ nlp = spacy.load("en_core_web_lg")
9
+ except:
10
+ script = "python -m spacy download en_core_web_lg"
11
+ os.system("bash -c '%s'" % script)
12
+ nlp = spacy.load("en_core_web_lg")
13
+
14
  #Import the libraries to support the model and predictions.
15
  from transformers import AutoTokenizer, AutoModelForSequenceClassification, TextClassificationPipeline
16
  import lime
 
35
 
36
  @st.experimental_singleton
37
  def prepare_model():
 
 
 
 
 
 
 
38
  tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english")
39
  model = AutoModelForSequenceClassification.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english")
40
  pipe = TextClassificationPipeline(model=model, tokenizer=tokenizer, return_all_scores=True)
41
+ return tokenizer, model, pipe
42
 
43
  @st.experimental_singleton
44
  def prepare_lists():
 
86
  text = st.text_input('Provide a sentence you want to evaluate.', placeholder = "I like you. I love you.", key="input")
87
 
88
  #Prepare the model, data, and Lime. Set starting variables.
89
+ tokenizer, model, pipe = prepare_model()
90
  countries, professions, word_lists = prepare_lists()
91
  explainer = set_up_explainer()
92
  text2 = ""