{"id":17692986,"url":"https://github.com/arsalan0c/mailsense","last_synced_at":"2025-03-30T22:46:19.885Z","repository":{"id":132662675,"uuid":"178587500","full_name":"arsalan0c/mailsense","owner":"arsalan0c","description":"A program to label emails with their sentiment as soon as they arrive in your inbox","archived":false,"fork":false,"pushed_at":"2019-08-10T11:13:36.000Z","size":241292,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-06T04:13:02.478Z","etag":null,"topics":["email","sentiment-classification"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/arsalan0c.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-03-30T17:03:29.000Z","updated_at":"2022-04-23T13:05:47.000Z","dependencies_parsed_at":"2023-04-10T17:01:25.273Z","dependency_job_id":null,"html_url":"https://github.com/arsalan0c/mailsense","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/arsalan0c%2Fmailsense","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arsalan0c%2Fmailsense/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arsalan0c%2Fmailsense/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arsalan0c%2Fmailsense/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arsalan0c","download_url":"https://codeload.github.com/arsalan0c/mailsense/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246390857,"owners_count":20769476,"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":["email","sentiment-classification"],"created_at":"2024-10-24T13:07:50.519Z","updated_at":"2025-03-30T22:46:17.308Z","avatar_url":"https://github.com/arsalan0c.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mailsense\n\n\u003e Subscribes to Gmail events to obtain new emails, performs sentiment analysis and then labels them.\n![](demo.gif)\n\n## Start\n1. clone this repo: `git clone --recurse-submodules https://github.com/arsalanc-v2/mailsense.git`\n2. `cd mailsense`\n3. Register a Google Cloud project with a Pub/Sub subscription here: https://console.cloud.google.com/\u003cbr/\u003e\nNote the project name, subscription name and topic name (last section of the ids)\n4. Download the Pub/Sub API credentials file from the cloud console\n5. Set Google Application Credentials: `export GOOGLE_APPLICATION_CREDENTIALS=/path/to/pubsub_credentials.json`\n6. Register your project with the Gmail API\n7. Download the Gmail API credentials file from the cloud console\n8. `pip install -r requirements.txt`\n9. Begin: `python3 mail/src/subscriber.py -p projectname -s subscriptionname -t topicname -cp /path/to/gmail_credentials.json -tp token.pickle -mt fastai -ma \"{'model_dir':'./mail/sample', 'model_name':'textclassifier.pkl'}\"`\n\nOn first run, you will be prompted to sign in and give the application access to view and modify your email.\n  \n## Scoring\nSentiment analysis is performed on an email's subject and a snippet of its body. \n\nThere are 3 possible predicted values:\n* `positive`\n* `neutral`\n* `negative`\n\nThe subject and body snippet are given the following scores according to their predicted sentiment:\n* `positive`: `1`,\n* `neutral`: `0`,\n* `negative`: `-1`\n\nThey are then weighted with the subject given a weight of `0.3` and the body snippet given a weight of `0.7`.\n\nThe weighted scores for the subject and body snippet are summed to determine the overall sentiment of the email:\n* `\u003e= 0.5`: `positive`\n* `\u003c 0.5 \u0026\u0026 \u003e -0.5`: `neutral`\n* `\u003c= -0.5`: `negative`\n\nTable of outcomes:\n\nSubject Sentiment | Body Snippet Sentiment | Overall Score | Overall Sentiment\n----------------- | ---------------------- | ------------- | -----------------\npositive          | positive               | 1.0           | positive\npositive          | neutral                | 0.3           | neutral\npositive          | negative               | -0.4          | neutral\nneutral           | positive               | 0.7           | positive\nneutral           | neutral                | 0.0           | neutral\nneutral           | negative               | -0.7          | negative\nnegative          | positive               | 0.4           | neutral\nnegative          | neutral                | -0.3          | neutral\nnegative          | negative               | -1.0          | negative\n\n## Models\nThe following sentiment analysis models are supported:\n\n* [fastai text classifier](https://docs.fast.ai/tutorial.data.html#Classification). Usage: `-mt fastai -ma \"{'model_dir': 'Directory of the saved fastai model', 'model_name': 'File name of the saved fastai model}\"`\n* [textblob Naive Bayes](https://textblob.readthedocs.io/en/dev/advanced_usage.html#sentiment-analyzers). Usage: `-mt textblob`\n* [nltk sentiment intensity analysis](https://www.nltk.org/api/nltk.sentiment.html). Usage: `-mt nltk`\n\nThe latter two models are not finetuned on any additional data and are used as imported.\u003cbr/\u003e\nEach of the models has an inference script:\u003cbr/\u003e\nEg. `python3 textblob/src/textblob_inference.py -t \"The spice must flow\"` prints `neutral`\n\n### Fastai\nA trained fastai model is provided at `mail/sample/textclassifier.pkl`.\nIt was trained on [EmoBank](https://github.com/JULIELab/EmoBank) and [Sentiment Labelled Sentences](https://archive.ics.uci.edu/ml/datasets/Sentiment+Labelled+Sentences). The one cycle policy was used in training to speed up training with a greater learning rate.\n\n[DVC](https://dvc.org/) was used to benchmark the training experiments with different model hyperparameters.\u003cbr/\u003e\nSee the pipeline: `dvc pipeline show fastai/dvc/evaluate_fastai.dvc --ascii`\u003cbr/\u003e\nReproduce the pipeline: `dvc repro fastai/dvc/evaluate_fastai.dvc`\n\n## Metrics\nSqlite (`mailsense.db`) is used to keep track of sentiment information:\n* label assigned to each email and its datetime (without email text)\n\nRun `python3 mail/src/metrics.py` to print some statistics to the console.\n\n## Logs\nThe operations in `mail.py` are logged and output to `mail/logs/mail.log`.\n\nIts general format is:\n\n`{description of operation} {(if applicable) specific info for operation, eg. sentiment label} {(if applicable) message with history id: {history id of a Gmail subscriber message}}`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farsalan0c%2Fmailsense","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farsalan0c%2Fmailsense","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farsalan0c%2Fmailsense/lists"}