{"id":13747228,"url":"https://github.com/minimaxir/reactionrnn","last_synced_at":"2025-04-06T13:09:46.264Z","repository":{"id":57460359,"uuid":"100954701","full_name":"minimaxir/reactionrnn","owner":"minimaxir","description":"Python module + R package to predict the reactions to a given text using a pretrained recurrent neural network.","archived":false,"fork":false,"pushed_at":"2019-02-10T15:25:53.000Z","size":1206,"stargazers_count":300,"open_issues_count":4,"forks_count":32,"subscribers_count":17,"default_branch":"master","last_synced_at":"2025-03-30T12:08:44.666Z","etag":null,"topics":["deep-learning","keras","r","sentiment-analysis","tensorflow"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/minimaxir.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-08-21T13:24:00.000Z","updated_at":"2025-03-14T21:29:36.000Z","dependencies_parsed_at":"2022-08-28T15:10:48.921Z","dependency_job_id":null,"html_url":"https://github.com/minimaxir/reactionrnn","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/minimaxir%2Freactionrnn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/minimaxir%2Freactionrnn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/minimaxir%2Freactionrnn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/minimaxir%2Freactionrnn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/minimaxir","download_url":"https://codeload.github.com/minimaxir/reactionrnn/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247485287,"owners_count":20946398,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deep-learning","keras","r","sentiment-analysis","tensorflow"],"created_at":"2024-08-03T06:01:21.269Z","updated_at":"2025-04-06T13:09:46.231Z","avatar_url":"https://github.com/minimaxir.png","language":"Python","funding_links":["https://www.patreon.com/minimaxir"],"categories":["Python"],"sub_categories":[],"readme":"# reactionrnn\n\nreactionrnn is a Python 2/3 module + R package on top of [Keras](https://github.com/fchollet/keras)/[TensorFlow](https://www.tensorflow.org) which can easily predict the proportionate reactions (love, wow, haha, sad, angry) to a given text using a pretrained recurrent neural network.\n\n```python\nfrom reactionrnn import reactionrnn\n\nreact = reactionrnn()\nreact.predict(\"Happy Mother's Day from the Chicago Cubs!\")\n```\n```\n[('love', 0.9765), ('wow', 0.0235), ('haha', 0.0), ('sad', 0.0), ('angry', 0.0)]\n```\n\nUnlike traditional sentiment analysis models using tools like [word2vec](https://en.wikipedia.org/wiki/Word2vec)/[doc2vec](https://radimrehurek.com/gensim/models/doc2vec.html), reactionrnn handles text at the character level, allowing it to incorporate capitalization, grammar, text length, and sarcasm in its predictions.\n\n```\n\u003e react.predict(\"This is scary AF!😱😱\")\n[('wow', 0.9109), ('sad', 0.0891), ('love', 0.0), ('haha', 0.0), ('angry', 0.0)]\n```\n\n```\n\u003e react.predict(\"When the soup is too hot 😂😂😂\")\n[('haha', 0.8568), ('love', 0.1376), ('wow', 0.0056), ('sad', 0.0), ('angry', 0.0)]\n```\n\n```\n\u003e react.predict(\"He was only 41.\")\n[('sad', 1.0), ('love', 0.0), ('wow', 0.0), ('haha', 0.0), ('angry', 0.0)]\n```\n\n```\n\u003e react.predict(\"Everyone loves autoplaying videos!\")\n[('angry', 0.8667), ('wow', 0.1333), ('love', 0.0), ('haha', 0.0), ('sad', 0.0)]\n```\n\nAs a bonus, the model can encode text as a 256D vector (incorporating grammar/caps/length/punc) which can then be fed into other machine learning/deep learning models.\n\n```\n\u003e react.encode(\"DYING. 😄\")\n[ 0.0411452   0.87985831  0.31406021, ...]\n```\n\nDid I mention that reactionrnn is also available as an R package with feature parity?\n\n```\nlibrary(reactionrnn)\nreact \u003c- reactionrnn()\nreact %\u003e% predict(\"Happy Mother's Day from the Chicago Cubs!\")\n```\n\n```\n      love        wow       haha        sad      angry \n0.97649449 0.02350551 0.00000000 0.00000000 0.00000000 \n```\n\n## Usage\n\nFor Python, reactionrnn can be installed [from pypi](https://pypi.python.org/pypi/reactionrnn) via `pip`:\n\n```\npython3 -m pip install reactionrnn\n```\n\nYou may need to create a venv (`python3 -m venv \u003cpath\u003e`) first.\n\nFor R, you can install reactionrnn from this GitHub repo with devtools (working on resolving issues to get package on CRAN):\n\n```\n# install.packages('devtools')\ndevtools::install_github(\"minimaxir/reactionrnn\", subdir=\"R-package\")\n```\n\nYou can view a demo of common features in [this Jupyter Notebook](/docs/reactionrnn-demo-python.ipynb) for Python, and [this R Notebook](http://minimaxir.com/notebooks/reactionrnn/) for R. (full documentation coming soon)\n\n## Neural Network Architecture and Implementation\n\n![](/docs/model_shapes.png)\n\nreactionrnn is based off of the June 2016 blog post I wrote titled [Classifying the Emotions of Facebook Posts Using Reactions Data](http://minimaxir.com/2016/06/interactive-reactions/), which noted that there is a certain nuance to the proportionality of the reactions on a Facebook status. What makes a Facebook post \"WOW\" but *not* \"HAHA\"? Is there a semantic difference between a post with 75% SAD and 90% SAD? A year later, Facebook now has enough public data to sufficiently train a neural network to understand these nuances.\n\nreactionrnn takes in an input of up to 140 characters (for compatability with Twitter tweets), converts each character to a 100D character embedding vector, and feeds those into a 256-cell [gated recurrent unit](https://en.wikipedia.org/wiki/Gated_recurrent_unit) layer. That output regresses the five non-Like Reactions all simultaneously and outputs the predicted proportionality values for each; predicted values will always sum to 1 (unlike Google's [Perspective API](https://www.perspectiveapi.com), the output is **not** the probability of the label as is the case with a classification model!)\n\nThe 1.3MB model weights included with the package are trained on the captions on hundreds of thousands of public Facebook statuses on Facebook Pages ([via my Facebook Page Post Scraper](https://github.com/minimaxir/facebook-page-post-scraper)), from a very *diverse* variety of subreddits/Pages (which is necessary since some Pages will have *very* different reactions to a given text!). The network was also trained in such a way that the `rnn` layer is decontextualized in order to both improve training performance and mitigate authorial and temporal biases toward given reactions.\n\nThe `encode` function of reactionrnn returns the intermediate 256D output from the 'rnn' layer.\n\n\n## Notes\n\n* Keep in mind that the network is trained on modern (2016-2017) language. As a result, inputting rhetorical/ironic statements will often yield love/wow responses and not sad/angry. \n\n* If a text sequence is \u003e140 characters, reactionrnn will only use the first 140 characters.\n\n* If you do use `encode` on multiple texts, I strongly recommend using [principal component analysis](https://en.wikipedia.org/wiki/Principal_component_analysis) to both reduce the high dimensionality of the text (i.e to 30-50D) and align the returned encoded texts. (see reactionrnn demos on how to implement PCA in Python and R)\n\n* A GPU is not required to use reactionrnn.\n\n## Future Plans for textgenrnn\n\n* A web-based implementation using Keras.js (works especially well due to the network's small size)\n\n* A larger pretrained network which can accommodate longer character sequences and a more indepth understanding of language, creating better/more robust reaction predictions. This may be released as a commercial product instead, if any venture capitalists are interested.\n\n## Maintainer/Creator\n\nMax Woolf ([@minimaxir](http://minimaxir.com))\n\n*Max's open-source projects are supported by his [Patreon](https://www.patreon.com/minimaxir). If you found this project helpful, any monetary contributions to the Patreon are appreciated and will be put to good creative use.*\n\n## Disclaimer\n\nreactionrnn is not supported by nor endorsed by Facebook.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fminimaxir%2Freactionrnn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fminimaxir%2Freactionrnn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fminimaxir%2Freactionrnn/lists"}