nltk

How to write all the sentences with the word "apple" from a txt file

How to write all the sentences with the word "apple" from a txt file Question: I have tried this using regex, loops and simple functions as well but cannot figure out anything. here are the few codes I have tried. import re fp = open("apple.txt") re.findall(r"([^.]*?apple[^.]*.)",fp) Asked By: chaitanya chitturi || Source Answers: with open("./WABA-crash.txt", …

Total answers: 2

An error in implementing regex function on a list

An error in implementing regex function on a list Question: I was trying to implement a regex on a list of grammar tags in python, for finding the tense form of the list of grammar. And I wrote the following code to implement it. Data preprocessing: from nltk import word_tokenize, pos_tag import nltk text = …

Total answers: 1

Bleu_score in NLTK library

Bleu_score in NLTK library Question: I am new to using the nltk library. I want to find the two most similar strings. In doing so, I used the ‘bleu_score’ as follows: import nltk from nltk.translate import bleu from nltk.translate.bleu_score import SmoothingFunction smoothie = SmoothingFunction().method4“` C1 = ‘FISSEN Ltds’ C2 = ‘FISSEN Ltds Maschinen- und Werkzeugbau’ …

Total answers: 1

Not able to assign values to a column. Bag_of_words

Not able to assign values to a column. Bag_of_words Question: I am trying to assign values to a column in my pandas df, however I am getting a blank column, here’s the code: df[‘Bag_of_words’] = ” columns = [‘genre’, ‘director’, ‘actors’, ‘key_words’] for index, row in df.iterrows(): words = ” for col in columns: words …

Total answers: 2

Chunking – regular expressions and trees

Chunking – regular expressions and trees Question: I’m a total noob so sorry if I’m asking something obvious. My question is twofold, or rather it’s two questions in the same topic: I’m studying nltk in Uni, and we’re doing chunks. In the grammar I have on my notes the following code: grammar = r""" NP: …

Total answers: 1

Re:sub expected string or byte-like object error

Re:sub expected string or byte-like object error Question: class REReplacer(object): def __init__(self, pattern = R_patterns): self.pattern = [(re.compile(regex), repl) for (regex, repl) in patterns] def replace(self, text): s = text for (pattern, repl) in self.pattern: s = re.sub(pattern, repl, s) return s I have got this code which replaces certain words with their replacements. When …

Total answers: 1

Find trigrams for all groupby clusters in a Pandas Dataframe and return in a new column

Find trigrams for all groupby clusters in a Pandas Dataframe and return in a new column Question: I’m trying to return the highest frequency trigram in a new column in a pandas dataframe for each group of keywords. (Essentially something like a groupby with transform, returning the highest trigram in a new column). An example …

Total answers: 1

Nltk is installed but nltk_utils returns ModuleNotFoundError

Nltk is installed but nltk_utils returns ModuleNotFoundError Question: I am using virtual env, I have installed nltk module with pip3, when I am trying to import nltk_utils I am getting a ModuleNotFoundError >>> import nltk >>> import nltk_utils Traceback (most recent call last): File "<stdin>", line 1, in <module> ModuleNotFoundError: No module named ‘nltk_utils’ I …

Total answers: 3

How do I add the result of a print function ito a list

How do I add the result of a print function ito a list Question: I have the follwing def what ends with a print function: from nltk.corpus import words nltk.download(‘words’) correct_spellings = words.words() from nltk.metrics.distance import jaccard_distance from nltk.util import ngrams from nltk.metrics.distance import edit_distance def answer_nine(entries=[‘cormulent’, ‘incendenece’, ‘validrate’]): for entry in entries: temp = …

Total answers: 2

What would the output of skip-gram model look like?

What would the output of skip-gram model look like? Question: To my understanding, the output of the skip-gram model must be compared with many training labels (depending on the window size) My question is: Does the final output of the skip-gram model look like the description in this picture? Ps. the most similar question I …

Total answers: 2