-
Notifications
You must be signed in to change notification settings - Fork 190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to get the impact of the words in the sentence on the emojis ? #32
Comments
@n0obcoder : It should be possible by using the attention vector that the model can return. Use the |
@setu4993 Hi, I tried this example and it throws me an error which is below: Traceback (most recent call last):
|
@vidyap-xgboost : Not sure why that would be caused. I could run that and get the attention vector. Do you mind sharing a more detailed code sample or Colab, and a little more about your environment? |
All I did was add the return_attention=True in /score_texts_emojis.py file. @setu4993 This is my Google Colab notebook |
@vidyap-xgboost: I see the problem. Once you add test_sentence = "This is a test sentence"
model = torchmoji_emojis(PRETRAINED_PATH, return_attention=True)
probabilities, attention_weights = model(st.tokenize_sentences([test_sentence])[0]) |
@vidyap-xgboost : If you want to continue using |
@setu4993 I tried both approaches and the first approach gave me a tensor object when I printed. Thank you for that! Now I understand which word carries what weight in predicting the output. However, as I am new to coding, I'm finding it a bit difficult to understand how I can write the attention_weights result to the CSV file. What should I change in the code in order to have the results written in the CSV? Thank you once again. |
@vidyap-xgboost : It depends on how you want to use it after exporting to CSV, what you want to store in the CSV, etc. Try looking at the Python documentation here for CSV operations. If you want to use it for non-PyTorch cases, you might want to store the tensors as numpy arrays or lists. |
I want to write every sentence I give it to a CSV file along with emojis and their attention weights. Thanks for your help. I will take it from here. :) |
Stumbled across this old issue. For future reference, the attention weights aren't that useful to getting the important words. It works better to do the sentence prediction w/o each word and see the difference, see more details here: https://huggingface.co/spaces/Pendrokar/DeepMoji/discussions/1#65eb375cdf813b9c15308c3c |
I am just curious that how can I get the impact of the words in the sentence that determines the respective emojis for the sentence, as shown in http://deepmoji.mit.edu/
Thanks in advance,
n0obcoder : D
The text was updated successfully, but these errors were encountered: