Is there method .predict in official python bindings for fastText
I know there are unofficial bindings with .predict method in python(fasttext, pyfasttext) but they do not work with recent models trained on on official FastText bash tool or do not have all the options. Official python bindings have only load_model(path)and tokenize(text) methods described , which sounds strange as with this you can not do any predictions. Am I missing something here?
I use the Python package built and installed according to this link https://github.com/facebookresearch/fastText/blob/master/README.md#building-fasttext-for-python. I consider it official. The model object loaded via load_model has the requested predict method.
See also questions close to this topic
How to use weigths extracted from a LSTM recurrent neural network
I have trained an LSTM recurrent neural network for sequence (time series) classification with Keras in Python.
Features are collated in a shape (batch_size, timesteps, data_dim). My training examples are 1000 in total. The final goal is to have a classification among 5 classes. Here is a snippet of my code.
#defining some model features data_dim = 15 timesteps = 20 num_classes = len(one_hot_train_labels[1,:]) batch_size = len(ytrain) #reshaping array for LSTM training xtrain=numpy.reshape(xtrain, (len(ytrain), timesteps, data_dim)) xtest=numpy.reshape(xtest, (len(ytest), timesteps, data_dim)) rms = optimizers.RMSprop(lr=0.001, rho=0.9, epsilon=None, decay=0.0) #It is recommended to leave the parameters #of this optimizer at their default values (except the learning rate, which can be freely tuned). # create the model model = Sequential() model.add(LSTM(101, dropout=0.5, recurrent_dropout=0.5, input_shape=(timesteps, data_dim), activation='tanh')) model.add(Dense(5, activation='softmax')) model.compile(loss='categorical_crossentropy', optimizer=rms, metrics=['accuracy']) print(model.summary()) history = model.fit(xtrain, one_hot_train_labels, epochs=200, batch_size=10) # Final evaluation of the model scores = model.evaluate(xtrain, one_hot_train_labels, verbose=0) print("Accuracy: %.2f%%" % (scores*100)) scores = model.evaluate(xtest, one_hot_test_labels, verbose=0) print("Accuracy: %.2f%%" % (scores*100))
Since I want to use and implement the classifier elsewhere, I have extracted the weights using:
weights = [model.get_weights() for layer in model.layers]
Having used traditional neural networks and logistic regression in the past, I was expecting 2 matrices for each layer, one with the polynomial weights and one with the bias units, and then using the activation function (in this case tanh and softmax function) to progressively find the probabilities of falling in one of the 5 classes.
But I am now confused because calling the weights returns me 5 matrices with the following sizes:
- (15, 400)
- (100, 400)
Now, I understand the LSTM works with 4 different blocks:
- input from vector
- memory from previous block
- memory from current block
- output from previous block
and hence why I have a size of 400 for the 2n dimension of my matrices.
And now my questions:
How can I use those weights in a cascade way to eventually get the class probabilities, using the activation functions (as in traditional neural networks)?
where is the bias unit for the input layer?
Thanks to everyone can help to clarify and help in understanding how to use this powerful tool as LSTM networks.
Hope this would be helpful not just for me.
Index based text clustering
Currently I am working on projet to cluster 2 millions of Text Memos. My objective is to create a standard for these Memos (Actually, when I say Memo, I mean text containing the description of something). To do so, I want first to cluster similar memos (gathering those which are probably having the same meaning) and then create a label for each cluster or group.
Since I am new to NLP, I want to know how to proceed to do so and what are some references / materials and similar projects that have been done before ?
I bet this a classic problem in NLP and many projects have been done about that subject.
I can work with R and Python
What is the multinomial logistic regression objective?
I have read two paper on convolutional
neural network, namely
VggNet. In both paper, I have read that the objective of training is to minimize/optimize "
multinomial logistic regression objective".
What does this mean?
comparing strings with user string
I saved a question
"What is your date of birth"
and when I asked
"When were you born"
I need to retrieve the same answer as
"what is your date of birth"
in node.js. Help me by solving it..
.What NLP libraries should I include or what steps should I follow?
What is the best way to implement a reply logic for a Chatbot
im a noob at making chatbots, and Im having some difficulties understanding how to make the bot reply back to queries and intents dynamically. My chatbot depends on replying back meaningful messages, more than fulfilling a request. Im was working with dialogflow but I thought Wit.ai would be more suitable, so I switched recently. But I still cant find how to train the bot to reply using RNN so it can first parse the intents, then reply back based on them. Any suggestions ? Kuddos.
Python create a custom dictionary for NLP analysis
I am fairly new to Python. I want to create a custom dictionary to consolidate a long (1Mil+ row) list of messy company names into cleaned names. Can I use the nltk package for this?
For example: I have the below transaction data with merchant names. I want to create a custom dictionary so I can classify the merchants names to cleaned ones.
- American Eagle#12455112 ---> American Eagle
- American Eag ---> American Eagle
- //##7555Banana Rep ---> Banana Republic
- New York H&M ---> H&M
- H&M Chigago ---> H&M
suicidal content identification machine learning and python
I'm working on a project of analysing the suicidal content of social media. currently, I have prepared data set for that. I need help for text classification for suicidal content using machine learning and python. I have googled a lot and couldn't find any result for that. can somebody give me a tutorial of step by step related to text classification for suicides or something?I'm very new to machine learning and text mining
Trying to run Classifier Model with New Data
I am getting my feet wet with Python and have built a text classifier that does pretty well with the test data. Now I'd like to run new data through the model via a CSV file. The CSV file has a description column that needs to be classified based on the training model. I tried the following code and get a "ValueError: X has 4478 features per sample; expecting 7474". It seems it is expecting the array the size of my training set. I could be trying this completely wrong. I'm just trying to add run a new CSV file through the model and then write the predictions to that new file. Since this uses the split method for test and train, I'm struggling on how actually implement the model for production use.
import pandas as pd df = pd.read_csv('Travel2.csv', nrows=25409) df.head() from io import StringIO col = ['Classification', 'LONG_DESCRIPTION'] df = df[col] df = df[pd.notnull(df['LONG_DESCRIPTION'])] df.columns = ['Classification', 'LONG_DESCRIPTION'] df['category_id'] = df['Classification'].factorize() category_id_df = df[['Classification', 'category_id']].drop_duplicates().sort_values('category_id') category_to_id = dict(category_id_df.values) id_to_category = dict(category_id_df[['category_id', 'Classification']].values) df.head() from sklearn.feature_extraction.text import TfidfVectorizer tfidf = TfidfVectorizer(sublinear_tf=True, min_df=5, norm='l2', encoding='latin-1', ngram_range=(1, 2), stop_words='english') features = tfidf.fit_transform(df.LONG_DESCRIPTION).toarray() labels = df.category_id features.shape from sklearn.model_selection import train_test_split from sklearn.svm import LinearSVC model = LinearSVC() X_train, X_test, y_train, y_test, indices_train, indices_test = train_test_split(features, labels, df.index, test_size=0.33, random_state=0) model.fit(X_train, y_train) y_pred = model.predict(X_test) '''New Data''' dfnew = pd.read_csv('2018cc.csv') dfnew.insert(2,'Prediction',"") dfnew.head() from sklearn.feature_extraction.text import TfidfVectorizer vect = TfidfVectorizer(sublinear_tf=True, min_df=5, norm='l2', encoding='latin-1', ngram_range=(1, 2), stop_words='english') x = vect.fit_transform(dfnew.LONG_DESCRIPTION).toarray() y = dfnew.Prediction x.shape from sklearn.svm import LinearSVC model = LinearSVC() model.fit(X_train, y_train) y = model.predict(x)
Sentiment classifier training with Keras
I am using keras (backend tensorflow) to classify sentiments from Amazon review.
It starts with an embedding layer (which uses GloVe), then LSTM layer and finally a Dense layer as output. Model summary below:
_________________________________________________________________ Layer (type) Output Shape Param # ================================================================= embedding_1 (Embedding) (None, None, 100) 2258700 _________________________________________________________________ lstm_1 (LSTM) (None, 16) 7488 _________________________________________________________________ dense_1 (Dense) (None, 5) 85 ================================================================= Total params: 2,266,273 Trainable params: 2,266,273 Non-trainable params: 0 _________________________________________________________________ Train on 454728 samples, validate on 113683 samples
When training the train and eval accuracy is about 74% and loss (train and eval) around 0.6.
I've tried with changing amount of elements in LSTM layer, as well as including dropout, recurrent dropout, regularizer, and with GRU (instead of LSTM). Then the accuracy increased a bit (~76%).
What else could I try in order to improve my results?
How exactly FastText suppose to improve chatbots?
I keep seeing articles stating that FastText library will revolutionize how chatbots are made and make them smarter, but I don't quite understand how? FastText was released in 2016 and there are still no (at least I couldn't find) pages describing how they would work with chatbots.
From the official FastText documentation and some other websites, I understood that the library can categorize sentences based on their content, which is great for finding spam or negative posts or determining the topics of it, but how does this help with bots having better responses?
I tried to classify possible inputs (just questions that the bot would answer), however it seems that datasets need to be large in order to have good results.
FastText bot, extracting/finding keywords/names/titles
I'm planning to build an information bot with FastText and NodejS. FastText allows to me to classify and determine that a user wants to find information about a product.
However, what would be the best way of extracting the product name out of the input? Should I just check every single word in the sentence and check if it matches with the list of products? Or is their a better way of doing so?