{"id":20917027,"url":"https://github.com/bluegranite/sentimentanalysisinpbiwithssmls","last_synced_at":"2026-03-18T02:34:39.391Z","repository":{"id":133234385,"uuid":"242170079","full_name":"BlueGranite/SentimentAnalysisInPBIWithSSMLS","owner":"BlueGranite","description":"Sentiment Analysis in Power BI with SQL Server Machine Learning Services","archived":false,"fork":false,"pushed_at":"2020-02-21T16:40:34.000Z","size":10,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-12-30T10:00:56.413Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BlueGranite.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2020-02-21T15:26:06.000Z","updated_at":"2021-06-25T17:41:36.000Z","dependencies_parsed_at":null,"dependency_job_id":"ea3b0656-f8f6-48c1-ad7d-70c5b52d3d65","html_url":"https://github.com/BlueGranite/SentimentAnalysisInPBIWithSSMLS","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/BlueGranite/SentimentAnalysisInPBIWithSSMLS","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlueGranite%2FSentimentAnalysisInPBIWithSSMLS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlueGranite%2FSentimentAnalysisInPBIWithSSMLS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlueGranite%2FSentimentAnalysisInPBIWithSSMLS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlueGranite%2FSentimentAnalysisInPBIWithSSMLS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BlueGranite","download_url":"https://codeload.github.com/BlueGranite/SentimentAnalysisInPBIWithSSMLS/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlueGranite%2FSentimentAnalysisInPBIWithSSMLS/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30642996,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-18T01:41:58.583Z","status":"online","status_checked_at":"2026-03-18T02:00:07.824Z","response_time":104,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-11-18T16:29:32.898Z","updated_at":"2026-03-18T02:34:39.348Z","avatar_url":"https://github.com/BlueGranite.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sentiment Analysis in Power BI via SQL Server Machine Learning Services using R or Python \n\nThe database you need to recreate the example used in the blog can be found in the database folder located in this repo. The example was done using R but if you want to use Python instead then you need to make sure that the Python version of the pre-trained models are installed in your database. The instructions to install the Python version can be found [here](https://bit.ly/38nROBI). Also you need to replace step 3 in the blog with the instructions that follows.\n\nSet the values of the ***@Query*** and ***@PythonScript*** variables. You need to set the @Query variable to a string that represents the T-SQL needed for your input dataset. You also need to set the @PythonScript variable to hold the Python code that will be used to perform the sentiment analysis. The T-SQL script for the @Query variable is as follows:\n\n```\n      SET @Query = 'SELECT [id], [text] FROM [dbo].[SentimentData]'\n```\n\nIt is a simple SELECT statement that grabs the data from the [dbo].[ SentimentData] table needed for our Python script. Next, we define the Python code needed to score the data. Here is the code:\n\n```\n      SET @PythonScript = '\nfrom microsoftml import rx_featurize, get_sentiment\n\nsentiment_scores = rx_featurize(\n    data=dfInput,\n    ml_transforms=[get_sentiment(cols=dict(scores=\"text\"))])\n\ndfOutput = sentiment_scores\n'\n```\n\nThe script is only three lines long because the pre-trained model does the heavy lifting. In the above Python script, the first line of code loads the necessary functions needed for this script. They are the ***rx_featurize()*** function and ***get_sentiment()*** function. The next line (actually the next three lines due to formatting) performs the sentiment analysis. The workhorse functions are the rxFeaturize() and getSentiment() functions from the microsoftml package. The rxFeaturize() function enables you to access data that has undergone a machine learning data transformation via microsoftml. It specifies the machine learning transformation that is being performed in the mlTransforms argument; which, in this example, is a getSentiment() transformation. The cols argument in getSentiment() is used to specify the columns in your dataset that you want to score. It uses a dictionary with the key of each ***key/value*** pair in the dictionary representing the name of the new column that will contain the sentiment scores and the value representing the the column that contains the text you are scoring. Please note that you can perform sentiment analysis on multiple columns at once. You just need to add the necessary key/value pairs to your dictionary using the method previously describe. The getSentiment() function will return a numeric value between 0 and 1 for each sentiment analysis it performs. The closer to 0 the value is, the more negative the sentiment, and the closer to 1 the value is, the more positive the sentiment.\n\nYou also need to make changes to ***step 4***. You just need to change the part of the code that referenced R to Python as illustrated below:\n\n```\n      EXEC sp_execute_external_script\n             @language = N'Python'\n            ,@input_data_1 = @Query\n            ,@input_data_1_name = @InputDFName\n            ,@output_data_1_name = @OutputDFName\n            ,@script = @PythonScript\n```\nThe ***SentimentAnalysisDB*** database contains two stored procedures. The ***dbo.getSentiments_R*** stored procedure uses R and ***dbo.getSentiments_Python*** stored procedure uses Python. Remember you need to make sure that ***SQL Server Machine Learning Services*** is installed in the database as well as the pre-trained models. Happy coding!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbluegranite%2Fsentimentanalysisinpbiwithssmls","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbluegranite%2Fsentimentanalysisinpbiwithssmls","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbluegranite%2Fsentimentanalysisinpbiwithssmls/lists"}