This repository was archived by the owner on Jan 8, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 59
Add code for sentiment analysis #417
Open
sanketverma1704
wants to merge
32
commits into
gramener:master
Choose a base branch
from
sanketverma1704:jd-transformers
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Required for fixing gramener#377 Since v0.24, sklearn's column transformers need the same order of feature names between .fit and .predict. We can still send URL parameters in any order, but they need to be ordered correctly by the MLHandler. See sklearn's release notes for more: https://scikit-learn.org/stable/whats_new/v0.24.html#sklearn-compose
…amex into jd-transformers
Contributor
|
Cool! @jaidevd could you please review? Do let me know when to merge |
Contributor
|
@MSanKeys963 The target branch has to be |
jaidevd
suggested changes
Jun 26, 2021
Contributor
|
@MSanKeys963 other than these two changes, LGTM |
Contributor
|
@MSanKeys963 this still showing merge conflicts. Please take a look. |
jaidevd
suggested changes
Jul 7, 2021
jaidevd
reviewed
Jul 13, 2021
Author
|
@jaidevd I've fixed all the issues mentioned above. Please let me know if there's anything else. |
Contributor
|
Thanks, @MSanKeys963 @sanand0 This is ready for merge. |
sanand0
reviewed
Jul 20, 2021
Author
|
@sanand0 I've fixed all the issues. Please check. |
Contributor
For example, this is how we optionally import ElasticSearch: def gramexlog(conf):
try:
from elasticsearch import Elasticsearch, helpers
except ImportError:
app_log.error('gramexlog: elasticsearch missing. pip install elasticsearch')
return |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Removed
class NLPHandler()and added sentiment analysis functionality inclass MLHandler().To setup a Gramex service for performing sentiment analysis, use the following configuration:
Getting predictions
GETsentiments of short pieces of text as follows:curl -X GET --data-urlencode "text=This movie is so bad, it's good." http://localhost:9988/The output will be:
[ { "label": "POSITIVE", "score": 0.9997316002845764 } ]Files containing text to be classified can also be
POSTed to the endpoint, with_action=predict. Any file supported bygramex.cache.openwill work. (Download a sample here.)The output will be:
[ { "label": "POSITIVE", "score": 0.9997316002845764 }, { "label": "NEGATIVE", "score": 0.9974692463874817 }, // etc. ]Measuring model performance
Files containing the
textandlabelfields can bePOSTEDto the endpointwith
_action=scoreto get the ROC AUC score of the model against the dataset. (Download a sample dataset here).The output will be something like:
{ "roc_auc": 0.9929 }Training the model
The model can be trained on a dataset by setting
_action=train, andPOSTing the file.The output will show the score of the trained model on the dataset:
{ "roc_auc": 0.8 }Multiple training options for the transformer are supported, including the number of epochs, batch size and weight decay. These can all be specified in the
POSTrequest as follows:The output is the score of the trained model on the dataset after 3 epochs:
{ "roc_auc": 0.98 }The output is the score of the trained model on the dataset after 3 epochs and a batch size of 32:
{ "roc_auc": 0.99 }