Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
|
|
25 |
elif method == "Word Embedding Substitution":
|
26 |
-
|
27 |
-
aug = naw.
|
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":
|