maximuspowers commited on
Commit
22eab0d
·
verified ·
1 Parent(s): c19dfc1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -18
app.py CHANGED
@@ -2,29 +2,15 @@ import gradio as gr
2
  import nlpaug.augmenter.word as naw
3
  import nlpaug.augmenter.char as nac
4
  import nlpaug.augmenter.sentence as nas
5
- import os
6
- import nltk
7
- from nlpaug.util.file.download import DownloadUtil
8
-
9
- # Download necessary NLTK resources
10
- nltk.download('averaged_perceptron_tagger')
11
- nltk.download('wordnet')
12
-
13
- # Function to download Word2Vec model if not available
14
- def download_word2vec():
15
- word2vec_path = "GoogleNews-vectors-negative300.bin"
16
- if not os.path.exists(word2vec_path):
17
- print("Downloading Word2Vec model...")
18
- DownloadUtil.download_word2vec(dest_dir='.')
19
- return word2vec_path
20
 
21
  # Function for NLP augmentation
22
  def augment_text(text, method):
23
  if method == "Synonym Replacement":
24
- aug = naw.SynonymAug(aug_src="wordnet", aug_max=3)
 
25
  elif method == "Word Embedding Substitution":
26
- word2vec_path = download_word2vec() # Ensure the model is downloaded
27
- aug = naw.WordEmbsAug(model_type='word2vec', model_path=word2vec_path, action="substitute")
28
  elif method == "Contextual Word Insertion":
29
  aug = naw.ContextualWordEmbsAug(model_path="bert-base-uncased", action="insert")
30
  elif method == "Back Translation":
 
2
  import nlpaug.augmenter.word as naw
3
  import nlpaug.augmenter.char as nac
4
  import nlpaug.augmenter.sentence as nas
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  # Function for NLP augmentation
7
  def augment_text(text, method):
8
  if method == "Synonym Replacement":
9
+ # Use BERT model for synonym replacement (contextual embeddings)
10
+ aug = naw.ContextualWordEmbsAug(model_path='bert-base-uncased', action='substitute')
11
  elif method == "Word Embedding Substitution":
12
+ # Use BERT for word embedding substitution instead of Word2Vec
13
+ aug = naw.ContextualWordEmbsAug(model_path='bert-base-uncased', action='substitute')
14
  elif method == "Contextual Word Insertion":
15
  aug = naw.ContextualWordEmbsAug(model_path="bert-base-uncased", action="insert")
16
  elif method == "Back Translation":