nltk

Find a specific concordance index using nltk

Find a specific concordance index using nltk Question: I use this code below to get a concordance from nltk and then show the indices of each concordance. And I get these results show below. So far so good. How do I look up the index of just one specific concordance? It is easy enough to …

Total answers: 2

operate over values of a dictionary when values are lists

operate over values of a dictionary when values are lists Question: Suppose I have the following dictionary: data = {‘ACCOUNT_CLOSURE’: [‘account closure’, ‘close account’, ‘close bank’, ‘terminate account’, ‘account deletion’, ‘cancel account’, ‘account cancellation’], ‘ACCOUNT_CHANGE’: [‘change my account’, ‘switch my account’, ‘change from private into savings’, ‘convert into family package’, ‘change title of the account’, …

Total answers: 1

How to reduce computational cost with Regex function

How to reduce computational cost with Regex function Question: I am trying to use regex to extract sentences containing specific words, and sentences before and next to them. My code works, but it takes 20 seconds for each txt and I have about a million txt files. Is it possible to get the same result …

Total answers: 2

SparseTermSimilarityMatrix().inner_product() throws "cannot unpack non-iterable bool object"

SparseTermSimilarityMatrix().inner_product() throws "cannot unpack non-iterable bool object" Question: While working with cosine similarity, I am facing issue calculating the inner product of two vectors. Code: from gensim.similarities import ( WordEmbeddingSimilarityIndex, SparseTermSimilarityMatrix ) w2v_model = api.load("glove-wiki-gigaword-50") similarity_index = WordEmbeddingSimilarityIndex(w2v_model) similarity_matrix = SparseTermSimilarityMatrix(similarity_index, dictionary) score = similarity_matrix.inner_product( X = [ (0, 1), (1, 1), (2, 1), (3, …

Total answers: 1

Text summarization of txt file using python

Text summarization of txt file using python Question: Any good code to summarize the text of one txt file and convert it to an output txt file in Python, I am working on a project open to any library like NLTK Asked By: KESHAV MAHESHWARI || Source Answers: It will require some tweaking to your …

Total answers: 1

Why does the nltk lemmatizer not work for every word in Python?

Why does the nltk lemmatizer not work for every word in Python? Question: import ntlk lemmatizer = ntlk.WordNetLemmatizer() print(lemmatizer.lemmatize("goes")) print(lemmatizer.lemmatize("transforming")) The first example will with "goes" do work. The output is: "go". The second does not work. I get the output "transforming" but should be "transform". Asked By: TheRi || Source Answers: You need to …

Total answers: 1

How to Tokenize block of text as one token in python?

How to Tokenize block of text as one token in python? Question: Recently I am working on a genome data set which consists of many blocks of genomes. On previous works on natural language processing, I have used sent_tokenize and word_tokenize from nltk to tokenize the sentences and words. But when I use these functions …

Total answers: 1

"Name or Service not known" while attaching to container

"Name or Service not known" while attaching to container Question: I’m dockerizin a flask app and everything works till container creation after that there is an error "Name or Service not known" Dockerfile: FROM python:3.10.8 COPY requirements.txt . RUN pip install -r requirements.txt RUN python -c "import nltk; nltk.download(‘averaged_perceptron_tagger’); nltk.download(‘wordnet’); nltk.download(‘omw-1.4’); nltk.download(‘stopwords’);" COPY . . …

Total answers: 1

How to increase count if function called by another function in Python

How to increase count if function called by another function in Python Question: I am trying to count all tokens given by func1 and print out the result from func2. The problem is that each time func2 gets called the counter does not update for natural reasons because we call the function over and over …

Total answers: 2

How do I retrieve phrases from a NLTK.tree using custom node labels?

How do I retrieve phrases from a NLTK.tree using custom node labels? Question: Given a NLTK tree produced using the code below, how do I retrieve the leaf values (phrases) that potentially match all of the node labels assigned using the nltk.RegexParser (e.g. those phrases which match the Present_Indefinite or Present_Perfect tense)? from nltk import …

Total answers: 1