Hot answers tagged

22

Here's the link for the methods available for fasttext implementation in gensim fasttext.py from gensim.models.wrappers import FastText model = FastText.load_fasttext_format('wiki.simple') print(model.most_similar('teacher')) # Output = [('headteacher', 0.8075869083404541), ('schoolteacher', 0.7955552339553833), ('teachers', 0.733420729637146), ('teaches',...


18

Thank Abhishek. I've figure it out! Here are my experiments. 1). we plot a easy example: from gensim.models import Word2Vec from sklearn.decomposition import PCA from matplotlib import pyplot # define training data sentences = [['this', 'is', 'the', 'first', 'sentence', 'for', 'word2vec'], ['this', 'is', 'the', 'second', 'sentence'], ...


12

For .bin use: load_fasttext_format() (this typically contains full model with parameters, ngrams, etc). For .vec use: load_word2vec_format (this contains ONLY word-vectors -> no ngrams + you can't update an model). Note:: If you are facing issues with the memory or you are not able to load .bin models, then check the pyfasttext model for the same. Credits ...


12

The title of this question is a separate question to its text so I will answer both separately (given that one leads into the other). How can I infer unseen sentences: # ... trained model stored in var model list_of_words = ["this", "is", "a", "new","unseen", "sentence"] inferred_embedding = model.infer_vector(list_of_words) How does this work ? As per ...


5

I've tried to explain the logic behind labels used in Document vectors in Doc2Vec - How to label the paragraphs (gensim) To answer your questions. 1) when two documents share the same label, then doc2vec algorithm determines the semantic meaning of the label from both the documents. Note that doc2vec learns the semantic meanings of labels not individual ...


5

That's an interesting problem. This according to me is the most comprehensive way(if speed is not a problem. Or you can just pull all these words and create a dictionary/database of your own). You can this , https://wordsapiv1.p.mashape.com/words/love/antonyms (More info about this API at this link) However, you can restrict results to antonyms with this ...


5

Increasing the number of epochs usually benefits the quality of the word representations. In experiments I have performed where the goal was to use the word embeddings as features for text classification setting the epochs to 15 instead of 5, increased the performance.


5

I have checked four well-cited papers related to word embedding: 2013 Word2Vec, 2014 GloVe, 2018 BERT, and 2018 ELMo. Only GloVe has experimented on the embedding dimension for the analogy task (answering "a" is to "b" as "c" is to ?). Other papers did not report an experiment on embedding dimension size. They are all using an arbitrary dimension on the ...


4

Let us look at a sample code: >>>from gensim.models import word2vec #let us train a sample model like yours >>>sentences = [['first', 'sentence'], ['second', 'sentence']] >>>model1 = word2vec.Word2Vec(sentences, min_count=1) #let this be the model from which you want to reset >>>sentences = [['third', 'sentence'], ['...


4

Word2Vec is not a combination of two models, rather both are variants of word2vec. Similarly doc2vec has Distributed Memory(DM) model and Distributed Bag of words (DBOW) model. Based on the context words and the target word, these variants arised. Note: the name of the model maybe confusing Distriubted Bag of words is similar to Skip-gram model ...


4

Except for the OCR part, the right bundle would be pandas and sklearn. You can check this ipython notebook which uses TfidfVectorizer and SVC Classifier. This classifier can make one-vs-one or one-vs-the-rest multiclass predictions, and if you use the predict_proba method instead of predict, you would have the confidence level of each category. If you're ...


4

You might find this paper might be the closest thing to what you are looking for if you don't want to treat it as a regular hyperparameter: Towards Lower Bounds on Number of Dimensions for Word Embeddings The paper claims that there is a lower bound on the embedding based on the corpus. It also purposes a method for finding said lower bound which I will ...


3

I believe that you misunderstood the word2vec concept. Basically for words, the feature vector for a word is learnt from the surrounding words. You shall know a word by the company it keeps- Firth.J.R In your case characters have been used, so the feature vector for each character depends upon the adjacent characters present. your example might work, if ...


3

Word2Vec can be used to find a word that relates to another word in the same way an example pair does. (fi: x is to happy, as bad is to good). You could use that to generate candidates of antonyms on the fly. It might not be as accurate as precompiled list, but it will cover almost every candidate. In fact Word2Vec could also help you find other (other than ...


3

The question has been answered in google groups by Gordon mohr. Normally there's one read of the corpus to build the vocabulary (which includes initializing the model based on the learned vocabulary size), then any number of extra passes for training. It's only after the one vocabulary-learning scan that word counts are looked at (and compared to min_count ...


3

I looked here, and found that the default value changed from 1 to 5. Apparently the authors believe that more epochs will improve the results. I cannot tell from experience, yet.


3

I will answer your second question first, doc2vec and word2vec both are primarily good representations of text data that capture the semantics of words and documents. So whenever you are working with text data, you need a representation for it and that is what word2vec and doc2vec provides. Now think of any real world task on text data, like document ...


3

The advantage of using pre-trained vectors is being able to inject knowledge from a larger corpus than you might have access to: word2vec has a vocabulary of 3 million words and phrases trained on the google news dataset comprising ~100 billion tokens, and there's no cost to you in training time. In addition, they are fast and easy to use, just load the ...


3

Add this line before training with the new terms. model.build_vocab([['potoatoes', 'and', 'farmers']], update=True) After training, print(len(model.wv.vocab)) => 8


3

Let us try and understand how Word2Vector actually works before looking at distances: There are 2 ways of generating vectors for a word : Continuous bag of words Skip grams The following diagram explains the difference between the two approaches. In case you want to further understand the nitty gritty of these two approaches, there are tons of blogs out ...


2

I trained my w2v model on google news 300 for [2, 10, 100] epochs and the best one was on 10 epochs. After all that waiting, I was shocked that 100 epochs was bad. epoch wall ------ ------ 2 56 s 10 4m 44s (284s) 100 47m 27s (2847 s)


2

If you are looking for a pre-trained net for word-embeddings, I would suggest GloVe. The following blog from Keras is very informative of how to implement this. It also has a link to the pre-trained GloVe embeddings. There are pre-trained word vectors ranging from a 50 dimensional vector to 300 dimensional vectors. They were built on either Wikipedia, Common ...


2

You can start with small lists of antonyms like this one. Maybe you can get a comprehensive list that will take care of most of the cases you are interested in. For now, let assume that you don't have such a list an discuss algorithmic ways to do it. As you wrote regarding prefixes like "un" and "dis", you can use rules based of morphology too. Such rules ...


2

If you have trained a gensim model, that object can act as a dictionary to give you the vector projection (via https://radimrehurek.com/gensim/models/word2vec.html) $ model['computer'] # raw numpy vector of a word array([-0.00449447, -0.00310097, 0.02421786, ...], dtype=float32) So it is possible to manually implement any vector comparison that you ...


2

For the example you pose, the answers and discussion on this question might be helpful - some good points on options around labelling: Doc2Vec - How to label the paragraphs (gensim)


2

The FastText binary format (which is what it looks like you're trying to load) isn't compatible with Gensim's word2vec format; the former contains additional information about subword units, which word2vec doesn't make use of. There's some discussion of the issue (and a workaround), on the FastText Github page. In short, you'll have to load the text format (...


2

I think you have it mostly correct. Word embeddings can be summed up by: A word is known by the company it keeps. You either predict the word given the context or vice versa. In either case similarity of word vectors is similarity in terms of replaceability. i.e. if two words are similar one could replace the other in the same context. Note that this means ...


2

As the gensim tool cites the very famous paper by Mikolov - "Distributed Representations of Words and Phrases..." using which it is implemented. In the paper if you look at the section "4 Learning Phrases" they give a nice explanation of how n-grams are calculated (Equation 6). So, if want to count bigrams this formula is straight-forward; score(wi, wj) is ...


2

Tensorflow has implementations for a pool of machine learning algorithms, so it should be comfortable if your application needs to build something on top of word2vec. Gensim is mainly intended for topic modelling techniques, but pretty robust as its their main work. If you want to get a clear grasp of how the algorithm works, then implementing manually ...


2

I actually do not think your method is a good way to find subtopics. Consider a document X with a distribution of topics z. X is made up of a mixed model distribution of topic Z. If you just give a document the most domiant distribution, and then run lda again, you might find subtopics but you'll also refind the topics that should should perhaps not be ...


Only top voted, non community-wiki answers of a minimum length are eligible