fine tune universal-sentence-encoder embeddings - python

I am new to NLP and Neural Networks. I want to do topic analysis for a dataset of reviews of our product. I tried to use the universal-sentence-encoder along with top2vec and they do a good job. However, the similarity score is low most of the time because the combination of words is unique. I want to retrain the model to capture the similarity in my dataset (which is about 40k reviews).
Is there a way to do so? I think this is called unsupervised fine-tuning
I am aware of Keras' API to import the transformer as a layer, but I do not how to continue from there.
Question 1: What layers or loses could I add to capture similarity between my reviews and outputs vector embedding of the text?
I also read about siamese networks. If I understood correctly, I can add the universal encoder twice as the common network, then add a layer for similarity like keras.layers.Dot.
Question 2: If I trained the model on every possible combination of me reviews, can I then use the output of the first embedding layers (with the new weights) as the embedding of text?
Question 3: If the answer for question is yes, both embeddings in the siamese networks should be almost identical for the same text. Right?

Related

How to create custom image embeddings on domain data without any target or labels for ranking similar images

0
I am looking for unsupervised image recommendation model approach and the data is too much domain specific and pre-trained models are not giving good results like Vgg, resnet, densenet, alexnet. The end task is to have several similar images in decreasing order of their resemblance as compared to the query image. One way is to fine-tune or create a CNN model but challenge is then their aren't any class or target labels. The other way is using a methodology if I can generate custom image embeddings then I believe I can directly use them against similarity metrices for their ranking rather than using a pre-trained model. The challenge is again how to generate custom image embeddings without any targets or classes. It would be nice if one can direct me towards unsupervised image recommendation models.

deep learning multi-task for multi datasets

I am implementing a speech emotion recognition multitask model in Pytorch. I see many researchers use single-input multi-output model in speech emotion recognition, but I want to realize the multi_input multi-output model. For this kind of model, I have seen some examples, they use different datasets as input, speech emotion recognition and gender recognition as output tasks. Although it is called multi-input multi-output model, but they concat the input information together in the following layers, which I thought can be regard as single-input.
I want to implement a model that can use several datasets as input and the input features in each datasets can be used predict the labels independently, which means for the output tasks, each task has its own input features, and input features of each dataset are corresponding to the each output tasks. How can I apply this to the model using Pytorch or Keras? Maybe if I don't concat features in all dataset, it can be worked. I don't know whether it is right.

How to build a Neural Network with sentence embeding concatenated to pre-trained CNN

I want to build a neural network that will take the feature map from the last layer of a CNN (VGG or resnet for example), concatenate an additional vector (for example , 1X768 bert vector) , and re-train the last layer on classification problem.
So the architecture should be like in:
but I want to concat an additional vector to each feature vector (I have a sentence to describe each frame).
I have 5 possible labels , and 100 frames in the input frames.
Can someone help me as to how to implement this type of network?
I would recommend looking into the Keras functional API.
Unlike a sequential model (which is usually enough for many introductory problems), the functional API allows you to create any acyclic graph you want. This means that you can have two input branches, one for the CNN (image data) and the other for any NLP you need to do (relating to the descriptive sentence that you mentioned). Then, you can feed in the combined outputs of these two branches into the final layers of your network and produce your result.
Even if you've already created your model using models.Sequential(), it shouldn't be too hard to rewrite it to use the functional API.
For more information and implementation details, look at the official documentation here: https://keras.io/guides/functional_api/

Using LDA Topic Models as a Classification Model Input

I made the LDA model to make topic model using big training data sets. So, I try to use this LDA model to classification using new sentence which it doesn't use in the training data set.
How I can find the most closet topic number using a new input sentence?
Should I use LDA Topic Models as a Classification Model Input?
Welcome to share example code using Python.
In classification problems, since the ground-truth label is known, we only need to consider how to extract features from the training data. For LDA, the features are usually the topic probability distribution, i.e. if there are 5 topics in the corpus, then the dimension of the feature vector is 5, and that should be a better feature than the closet topic number (the most probable topic).
For how to get topic probability distribution for new input sentences, you can take a look at here, for other packages, they should also have similar functions.

Difference between pre-trained word embedding and training word embedding in keras

I am new to Deep Learning and I want to explore Deep Learning for NLP. I went through word embeddings and tested them in gensim word2vec. I also heard about pre-trained models. I am confused about the difference between pre-trained models and training the model yourself, and how to use the results.
I want to apply it in keras because I do not want to write formulas and all in Theano or Tensorflow.
When training word2vec with gensim, the result you achieve is a representation of the words in your vocabulary as vectors. The dimension of these vectors is the size of the neural network.
The pre-trained word2vec models simply contain a list of those vectors that were pre-trained on a large corpus. You will find pre-trained vectors of various sizes.
How to use those vector representations? That depends on what you want to do. Some interesting properties have been shown for these vectors: it has been shown that the vector for 'man' + 'king' - 'woman' will often result in the closest match to the vector 'woman'. You may also consider using the word vectors as input for another neural network/computation model.
Gensim is a very optimized library to perform the CBOW and skip-gram algorithms but if you really want to set up your neural network yourself, you will first have to learn about the structure of CBOW and skip-gram and learn how to code it in keras for example. This should not be particularly complex and a google search for these subjects should provide you with many results to help you along.

Categories

Resources