Как заменить слова их синонимами word-net? - PullRequest
0 голосов
/ 18 октября 2018

Я хочу выполнить увеличение данных для задачи анализа настроений, заменив слова синонимами из wordnet, но замена происходит случайным образом. Я хочу зациклить синонимы и заменить слово всеми синонимами по одному, чтобы увеличить размер данных

sentences=[]
for index , r in pos_df.iterrows():
  text=normalize(r['text'])
  words=tokenize(text)
  output = ""
  # Identify the parts of speech
  tagged = nltk.pos_tag(words)

  for i in range(0,len(words)):
      replacements = []

      # Only replace nouns with nouns, vowels with vowels etc.
      for syn in wordnet.synsets(words[i]):    
           # Do not attempt to replace proper nouns or determiners
          if tagged[i][1] == 'NNP' or tagged[i][1] == 'DT':
              break

          # The tokenizer returns strings like NNP, VBP etc
          # but the wordnet synonyms has tags like .n.
          # So we extract the first character from NNP ie n
          # then we check if the dictionary word has a .n. or not 
          word_type = tagged[i][1][0]

          if syn.name().find("."+word_type+"."):
              # extract the word only
              r = syn.name()[0:syn.name().find(".")]
              replacements.append(r)

      if len(replacements) > 0:
          # Choose a random replacement
          replacement = replacements[randint(0,len(replacements)-1)]
          print(replacement)
          output = output + " " + replacement
      else:
          # If no replacement could be found, then just use the
          # original word
          output = output + " " + words[i]

  sentences.append([output,'positive'])

1 Ответ

0 голосов
/ 09 мая 2019

Даже я работаю с проектом подобного типа, генерирую новые предложения из заданного ввода, но не меняя контекст из текста ввода.Столкнувшись с этим, я нашел метод увеличения данных.Который, кажется, хорошо работает на части дополнения.EDA (Easy Data Augmentation) - это документ [https://github.com/jasonwei20/eda_nlp].

Надеюсь, это поможет вам.

...