ahnaftaz commited on
Commit
05a84b7
·
verified ·
1 Parent(s): 51bd4e7

add 4 rows (bf6153efb4e5)

Browse files
shards/9abe615424f1/split-11-of-16/band-07/commit-doc-00000010-bf6153efb4e5edfe.jsonl ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {"annotations":{"commit_quality_band":"07","commit_quality_score":{"commit_score":0,"deductions":[{"points":2,"reason":"throwaway_message"}],"repo_score":2,"repo_score_components":{"dependents_reach":0,"gitstar_rank_present":2,"gitstar_rank_top_1000":0,"route_family_breadth":0,"route_language_top10":0},"rubric_version":2,"tier":7},"conventional_commit_type":{"breaking":false,"has_body":false,"issue_references":[],"message_words":2,"scope":null,"subject_length":45,"trailer_names":[],"type":null},"patch_statistics":{"added_lines":7,"context_bytes":3340,"deleted_lines":8,"files_changed":1,"hunk_count":2,"patch_bytes":1412,"patch_sha256":"5c6cbf4ac4eea654ea32492b67fa22b0181ce731d63a141ea81044e55ece3e5d"},"possible_ai_authorship":{"matched":[],"pattern_version":1,"signal":"no_named_signal_detected"},"programming_languages":{"files":[{"language":"sql","path":"samples/features/machine-learning-services/python/sentiment-analysis/pretrainedmodel_sentiment_analysis.sql","purpose":"source"}],"primary_language":"sql"},"quality_band":"07","tests_touched":{"source_files_also_touched":true,"test_files":[],"touched":false},"verification_state":"parent_reconstructed"},"id":"commit-doc:github.com/microsoft/sql-server-samples@5b701628af814e0f8aaba355f7dcbe4333a5a618","meta":{"change_summary":{"before_state_bytes":3340,"coverage":"all_files_of_the_commit_seen","files_in_original_commit":1,"files_kept":1,"patch_bytes":1412},"commit_oid":"5b701628af814e0f8aaba355f7dcbe4333a5a618","identity":{"author_email":"uc-msft@users.noreply.github.com","author_name":"Umachandar Jayachandran","authored_at":"2017-10-30T22:06:36-07:00","commit_oid":"5b701628af814e0f8aaba355f7dcbe4333a5a618","commits_ago_from_head":2881,"committed_at":"2017-10-30T22:06:36-07:00","committer_email":"noreply@github.com","committer_name":"GitHub","parent_oid":"0d8ee70374f59cee712fdad85dec170c4eba02a8","tree_oid":"3091b6804a5084ea114cb1d8905031c30a2e8b3f"},"pipeline_log":[],"proof":{"replay_audit":{"failed_paths":[],"outcome":"not_sampled","sampled":false},"verification_state":"parent_reconstructed"},"repository":{"default_branch":"master","history_collected":{"commits_read":4110,"commits_skipped_parent_beyond_cutoff":null,"merge_commits_skipped":null,"newest_commit":"1ab31bc560415b570d57bb5ff9896f4698891321","oldest_commit":"0cd204129c9b9674c31837bf857059be782bbdeb"},"recorded_head_commit":"1ab31bc560415b570d57bb5ff9896f4698891321","repository_id":"github.com/microsoft/sql-server-samples","snapshot_check":"matches_recorded_head"},"repository_id":"github.com/microsoft/sql-server-samples","shape":"commit","source":{"discovery_routes":null,"manifest_position":97035,"manifest_sha256":null,"split":"11-of-16"}},"parents":["commit:github.com/microsoft/sql-server-samples@5b701628af814e0f8aaba355f7dcbe4333a5a618__download_changed_file_contents_801a0f2d457b__render_commit_patches_959ce5297726"],"payload":{"changed_files":[{"before_content":"/*\nTo install the pretrained model in SQL Server, open an elevated CMD promtp:\n1. Navigate to the SQL Server installation path: \nC:\\<SQL SERVER Installation path>\\Microsoft SQL Server\\140\\Setup Bootstrap\\SQL2017\\x64\n2. Run the following command: \nRSetup.exe /install /component MLM /<version>/language 1033 /destdir <SQL_DB_instance_folder>\\PYTHON_SERVICES\\Lib\\site-packages\\microsoftml\\mxLibs\nExample:\nRSetup.exe /install /component MLM /version 9.2.0.24 /language 1033 /destdir \"C:\\Program Files\\Microsoft SQL Server\\MSSQL14.MSSQLSERVER\\PYTHON_SERVICES\\Lib\\site-packages\\microsoftml\\mxLibs\"\nThe models will be downloaded and extracted.\n*/\n\n\nUSE [tpcxbb_1gb]\nGO\n\n--******************************************************************************************************************\n-- STEP 1 Stored procedure that uses a pretrained model to determine sentiment of a text, such as a product review\n--******************************************************************************************************************\nCREATE OR ALTER PROCEDURE [dbo].[get_sentiment] \n(@text NVARCHAR(MAX))\nAS\nBEGIN\n\tDECLARE\t@script nvarchar(max);\n\n--Check that text is not empty\nIF NULLIF(@text, '') is null \nBEGIN\nTHROW 50001, 'Please specify a text value to be analyzed.', 1; \nRETURN\nEND\t\n\n\n\t--The Python script we want to execute\n\tSET @script = N'\nimport pandas as p\nfrom microsoftml import rx_featurize, get_sentiment\n\nanalyze_this = text\n\n# Create the data\ntext_to_analyze = p.DataFrame(data=dict(Text=[analyze_this]))\n\n# Get the sentiment scores\nsentiment_scores = rx_featurize(data=text_to_analyze,ml_transforms=[get_sentiment(cols=dict(scores=\"Text\"))])\n\n# Lets translate the score to something more meaningful\nsentiment_scores[\"Sentiment\"] = sentiment_scores.scores.apply(lambda score: \"Positive\" if score > 0.6 else \"Negative\")\n';\n\t\n\tEXECUTE sp_execute_external_script\n\t\t\t\t@language = N'Python'\n\t\t\t\t, @script = @script\n\t\t\t\t, @output_data_1_name = N'sentiment_scores'\n\t\t\t\t, @params = N'@text nvarchar(max)'\n\t\t\t\t, @text = @text\n\t\t\t\tWITH RESULT SETS ((\"Text\" NVARCHAR(MAX),\"Score\" FLOAT, \"Sentiment\" NVARCHAR(30)));\t\t\t\n\nEND\n\t\t\t\t \nGO\n\n--******************************************************************************************************************\n-- STEP 2 Execute the stored procedure to get sentiment of your own text\n--The below examples test a negative and a positive review text\n--******************************************************************************************************************\n-- Negative review\nEXECUTE [dbo].[get_sentiment] N'These are not a normal stress reliever. First of all, they got sticky, hairy and dirty on the first day I received them. Second, they arrived with tiny wrinkles in their bodies and they were cold. Third, their paint started coming off. Fourth when they finally warmed up they started to stick together. Last, I thought they would be foam but, they are a sticky rubber. If these were not rubber, this review would not be so bad.';\nGO\n\n--Positive review\nEXECUTE [dbo].[get_sentiment] N'These are the cutest things ever!! Super fun to play with and the best part is that it lasts for a really long time. So far these have been thrown all over the place with so many of my friends asking to borrow them because they are so fun to play with. Super soft and squishy just the perfect toy for all ages.'\nGO","before_content_lossy":false,"new_mode":"100644","new_oid":"5c118f8bd3b5ef818f78afd3c1f96ec4efde8d4c","numstat":{"added":7,"deleted":8},"old_mode":"100644","old_oid":"f4b129b2701331a540107a1c1be0325b5ea9e0f8","path":"samples/features/machine-learning-services/python/sentiment-analysis/pretrainedmodel_sentiment_analysis.sql","path_bytes_base64":null,"path_lossy":false,"status":"M","unified_patch":"diff --git a/samples/features/machine-learning-services/python/sentiment-analysis/pretrainedmodel_sentiment_analysis.sql b/samples/features/machine-learning-services/python/sentiment-analysis/pretrainedmodel_sentiment_analysis.sql\nindex f4b129b2701331a540107a1c1be0325b5ea9e0f8..5c118f8bd3b5ef818f78afd3c1f96ec4efde8d4c 100644\n--- a/samples/features/machine-learning-services/python/sentiment-analysis/pretrainedmodel_sentiment_analysis.sql\n+++ b/samples/features/machine-learning-services/python/sentiment-analysis/pretrainedmodel_sentiment_analysis.sql\n@@ -22,13 +22,12 @@ AS\n BEGIN\n \tDECLARE\t@script nvarchar(max);\n \n---Check that text is not empty\n-IF NULLIF(@text, '') is null \n-BEGIN\n-THROW 50001, 'Please specify a text value to be analyzed.', 1; \n-RETURN\n-END\t\n-\n+\t--Check that text is not empty\n+\tIF NULLIF(@text, '') is null \n+\tBEGIN\n+\t\tTHROW 50001, 'Please specify a text value to be analyzed.', 1; \n+\t\tRETURN\n+\tEND\n \n \t--The Python script we want to execute\n \tSET @script = N'\n@@ -69,4 +68,4 @@ GO\n \n --Positive review\n EXECUTE [dbo].[get_sentiment] N'These are the cutest things ever!! Super fun to play with and the best part is that it lasts for a really long time. So far these have been thrown all over the place with so many of my friends asking to borrow them because they are so fun to play with. Super soft and squishy just the perfect toy for all ages.'\n-GO\n\\n+GO\n","unified_patch_lossy":false}],"message":"Update pretrainedmodel_sentiment_analysis.sql","message_lossy":false},"provenance":{"clone_url":"https://github.com/microsoft/sql-server-samples","commit_oid":"5b701628af814e0f8aaba355f7dcbe4333a5a618","commits_ago_from_head":2881,"content_sha256":"83d5d8255fc0991a2824778c1f01b292f5b17d4932e2684fa5b1ee6e85cc3a4f","manifest_sha256":null,"parent_oid":"0d8ee70374f59cee712fdad85dec170c4eba02a8","repository_id":"github.com/microsoft/sql-server-samples","shape":"commit"},"schema_version":"locus.item/v1"}
2
+ {"annotations":{"commit_quality_band":"07","commit_quality_score":{"commit_score":0,"deductions":[{"points":2,"reason":"throwaway_message"}],"repo_score":2,"repo_score_components":{"dependents_reach":0,"gitstar_rank_present":2,"gitstar_rank_top_1000":0,"route_family_breadth":0,"route_language_top10":0},"rubric_version":2,"tier":7},"conventional_commit_type":{"breaking":false,"has_body":false,"issue_references":[],"message_words":3,"scope":null,"subject_length":25,"trailer_names":[],"type":null},"patch_statistics":{"added_lines":16,"context_bytes":2345,"deleted_lines":2,"files_changed":1,"hunk_count":2,"patch_bytes":2248,"patch_sha256":"3caee83acaa904508747dfdf3e6f0b55ca50fe5fb634fdd69535c23a53aa9767"},"possible_ai_authorship":{"matched":[],"pattern_version":1,"signal":"no_named_signal_detected"},"programming_languages":{"files":[{"language":"sql","path":"samples/features/machine-learning-services/python/sentiment-analysis/pretrainedmodel_sentiment_analysis.sql","purpose":"source"}],"primary_language":"sql"},"quality_band":"07","tests_touched":{"source_files_also_touched":true,"test_files":[],"touched":false},"verification_state":"parent_reconstructed"},"id":"commit-doc:github.com/microsoft/sql-server-samples@a851aa7aabea550033af911ace5dc3ef9b17f612","meta":{"change_summary":{"before_state_bytes":2345,"coverage":"all_files_of_the_commit_seen","files_in_original_commit":1,"files_kept":1,"patch_bytes":2248},"commit_oid":"a851aa7aabea550033af911ace5dc3ef9b17f612","identity":{"author_email":"negust@microsoft.com","author_name":"nelgson","authored_at":"2017-10-30T22:00:58-07:00","commit_oid":"a851aa7aabea550033af911ace5dc3ef9b17f612","commits_ago_from_head":2883,"committed_at":"2017-10-30T22:00:58-07:00","committer_email":"negust@microsoft.com","committer_name":"nelgson","parent_oid":"d729518369f44543cf5f4833c54dde9a99731dec","tree_oid":"ab748e62b2b8445ff17a8d061a349c8cdde28e2f"},"pipeline_log":[],"proof":{"replay_audit":{"failed_paths":[],"outcome":"not_sampled","sampled":false},"verification_state":"parent_reconstructed"},"repository":{"default_branch":"master","history_collected":{"commits_read":4110,"commits_skipped_parent_beyond_cutoff":null,"merge_commits_skipped":null,"newest_commit":"1ab31bc560415b570d57bb5ff9896f4698891321","oldest_commit":"0cd204129c9b9674c31837bf857059be782bbdeb"},"recorded_head_commit":"1ab31bc560415b570d57bb5ff9896f4698891321","repository_id":"github.com/microsoft/sql-server-samples","snapshot_check":"matches_recorded_head"},"repository_id":"github.com/microsoft/sql-server-samples","shape":"commit","source":{"discovery_routes":null,"manifest_position":97035,"manifest_sha256":null,"split":"11-of-16"}},"parents":["commit:github.com/microsoft/sql-server-samples@a851aa7aabea550033af911ace5dc3ef9b17f612__download_changed_file_contents_309481540a9f__render_commit_patches_a325069f69b7"],"payload":{"changed_files":[{"before_content":"/*\nTo install the pretrained model in SQL Server, open an elevated CMD promtp:\n1. Navigate to the SQL Server installation path: \nC:\\<SQL SERVER Installation path>\\Microsoft SQL Server\\140\\Setup Bootstrap\\SQL2017\\x64\n2. Run the following command: \nRSetup.exe /install /component MLM /<version>/language 1033 /destdir <SQL_DB_instance_folder>\\PYTHON_SERVICES\\Lib\\site-packages\\microsoftml\\mxLibs\nExample:\nRSetup.exe /install /component MLM /version 9.2.0.24 /language 1033 /destdir \"C:\\Program Files\\Microsoft SQL Server\\MSSQL14.MSSQLSERVER\\PYTHON_SERVICES\\Lib\\site-packages\\microsoftml\\mxLibs\"\nThe models will be downloaded and extracted.\n*/\n\n\nUSE [tpcxbb_1gb]\nGO\n\n--******************************************************************************************************************\n-- STEP 1 Stored procedure that uses a pretrained model to determine sentiment of a text, such as a product review\n--******************************************************************************************************************\nCREATE OR ALTER PROCEDURE [dbo].[get_sentiment] \n(@text NVARCHAR(MAX))\nAS\nBEGIN\n\tDECLARE\t@script nvarchar(max);\n\t\n\t--The Python script we want to execute\n\tSET @script = N'\nimport pandas as p\nfrom microsoftml import rx_featurize, get_sentiment\n\nanalyze_this = text\n\n# Create the data\ntext_to_analyze = p.DataFrame(data=dict(Text=[analyze_this]))\n\n# Get the sentiment scores\nsentiment_scores = rx_featurize(data=text_to_analyze,ml_transforms=[get_sentiment(cols=dict(scores=\"Text\"))])\n\n# Lets translate the score to something more meaningful\nsentiment_scores[\"Sentiment\"] = sentiment_scores.scores.apply(lambda score: \"Positive\" if score > 0.6 else \"Negative\")\n';\n\t\n\tEXECUTE sp_execute_external_script\n\t\t\t\t@language = N'Python'\n\t\t\t\t, @script = @script\n\t\t\t\t, @output_data_1_name = N'sentiment_scores'\n\t\t\t\t, @params = N'@text nvarchar(max)'\n\t\t\t\t, @text = @text\n\t\t\t\tWITH RESULT SETS ((\"Text\" NVARCHAR(MAX),\"Score\" FLOAT, \"Sentiment\" NVARCHAR(30)));\t\t\t\n\nEND\n\t\t\t\t \nGO\n\n--******************************************************************************************************************\n-- STEP 2 Execute the stored procedure to get sentiment of your own text\n--******************************************************************************************************************\nEXECUTE [dbo].[get_sentiment] N'ENTER YOUR OWN TEXT HERE';\nGO\n","before_content_lossy":false,"new_mode":"100644","new_oid":"f4b129b2701331a540107a1c1be0325b5ea9e0f8","numstat":{"added":16,"deleted":2},"old_mode":"100644","old_oid":"53187f211696840e31d09c9aa576d3fc83556035","path":"samples/features/machine-learning-services/python/sentiment-analysis/pretrainedmodel_sentiment_analysis.sql","path_bytes_base64":null,"path_lossy":false,"status":"M","unified_patch":"diff --git a/samples/features/machine-learning-services/python/sentiment-analysis/pretrainedmodel_sentiment_analysis.sql b/samples/features/machine-learning-services/python/sentiment-analysis/pretrainedmodel_sentiment_analysis.sql\nindex 53187f211696840e31d09c9aa576d3fc83556035..f4b129b2701331a540107a1c1be0325b5ea9e0f8 100644\n--- a/samples/features/machine-learning-services/python/sentiment-analysis/pretrainedmodel_sentiment_analysis.sql\n+++ b/samples/features/machine-learning-services/python/sentiment-analysis/pretrainedmodel_sentiment_analysis.sql\n@@ -21,7 +21,15 @@ CREATE OR ALTER PROCEDURE [dbo].[get_sentiment]\n AS\n BEGIN\n \tDECLARE\t@script nvarchar(max);\n-\t\n+\n+--Check that text is not empty\n+IF NULLIF(@text, '') is null \n+BEGIN\n+THROW 50001, 'Please specify a text value to be analyzed.', 1; \n+RETURN\n+END\t\n+\n+\n \t--The Python script we want to execute\n \tSET @script = N'\n import pandas as p\n@@ -53,6 +61,12 @@ GO\n \n --******************************************************************************************************************\n -- STEP 2 Execute the stored procedure to get sentiment of your own text\n+--The below examples test a negative and a positive review text\n --******************************************************************************************************************\n-EXECUTE [dbo].[get_sentiment] N'ENTER YOUR OWN TEXT HERE';\n+-- Negative review\n+EXECUTE [dbo].[get_sentiment] N'These are not a normal stress reliever. First of all, they got sticky, hairy and dirty on the first day I received them. Second, they arrived with tiny wrinkles in their bodies and they were cold. Third, their paint started coming off. Fourth when they finally warmed up they started to stick together. Last, I thought they would be foam but, they are a sticky rubber. If these were not rubber, this review would not be so bad.';\n GO\n+\n+--Positive review\n+EXECUTE [dbo].[get_sentiment] N'These are the cutest things ever!! Super fun to play with and the best part is that it lasts for a really long time. So far these have been thrown all over the place with so many of my friends asking to borrow them because they are so fun to play with. Super soft and squishy just the perfect toy for all ages.'\n+GO\n\\n","unified_patch_lossy":false}],"message":"Updated pretrained script\n","message_lossy":false},"provenance":{"clone_url":"https://github.com/microsoft/sql-server-samples","commit_oid":"a851aa7aabea550033af911ace5dc3ef9b17f612","commits_ago_from_head":2883,"content_sha256":"376b496645a2f3551deacf0b6c7d4013bc21b5ae23e93a76da6368e3a34b5b91","manifest_sha256":null,"parent_oid":"d729518369f44543cf5f4833c54dde9a99731dec","repository_id":"github.com/microsoft/sql-server-samples","shape":"commit"},"schema_version":"locus.item/v1"}
3
+ {"annotations":{"commit_quality_band":"07","commit_quality_score":{"commit_score":2,"deductions":[],"repo_score":2,"repo_score_components":{"dependents_reach":0,"gitstar_rank_present":2,"gitstar_rank_top_1000":0,"route_family_breadth":0,"route_language_top10":0},"rubric_version":2,"tier":7},"conventional_commit_type":{"breaking":false,"has_body":false,"issue_references":[],"message_words":5,"scope":null,"subject_length":23,"trailer_names":[],"type":null},"patch_statistics":{"added_lines":2,"context_bytes":8717,"deleted_lines":0,"files_changed":2,"hunk_count":2,"patch_bytes":1830,"patch_sha256":"3fab2a34e7c34ab8451e46fb9121b4150d6537688d3c0cbf3d2b579e38bfad86"},"possible_ai_authorship":{"matched":[],"pattern_version":1,"signal":"no_named_signal_detected"},"programming_languages":{"files":[{"language":"sql","path":"samples/features/machine-learning-services/python/sentiment-analysis/product-review-pretrained-model-sentiment-analysis.sql","purpose":"source"},{"language":"sql","path":"samples/features/machine-learning-services/python/sentiment-analysis/product-review-text-classification.sql","purpose":"source"}],"primary_language":"sql"},"quality_band":"07","tests_touched":{"source_files_also_touched":true,"test_files":[],"touched":false},"verification_state":"parent_reconstructed"},"id":"commit-doc:github.com/microsoft/sql-server-samples@d729518369f44543cf5f4833c54dde9a99731dec","meta":{"change_summary":{"before_state_bytes":8717,"coverage":"all_files_of_the_commit_seen","files_in_original_commit":2,"files_kept":2,"patch_bytes":1830},"commit_oid":"d729518369f44543cf5f4833c54dde9a99731dec","identity":{"author_email":"negust@microsoft.com","author_name":"nelgson","authored_at":"2017-10-30T21:31:23-07:00","commit_oid":"d729518369f44543cf5f4833c54dde9a99731dec","commits_ago_from_head":2884,"committed_at":"2017-10-30T21:31:23-07:00","committer_email":"negust@microsoft.com","committer_name":"nelgson","parent_oid":"059bbee1f866d9cccad00574faa877df235bb1ab","tree_oid":"a4197b01667bcb5a27e26f1eb911df930cea9a98"},"pipeline_log":[],"proof":{"replay_audit":{"failed_paths":[],"outcome":"not_sampled","sampled":false},"verification_state":"parent_reconstructed"},"repository":{"default_branch":"master","history_collected":{"commits_read":4110,"commits_skipped_parent_beyond_cutoff":null,"merge_commits_skipped":null,"newest_commit":"1ab31bc560415b570d57bb5ff9896f4698891321","oldest_commit":"0cd204129c9b9674c31837bf857059be782bbdeb"},"recorded_head_commit":"1ab31bc560415b570d57bb5ff9896f4698891321","repository_id":"github.com/microsoft/sql-server-samples","snapshot_check":"matches_recorded_head"},"repository_id":"github.com/microsoft/sql-server-samples","shape":"commit","source":{"discovery_routes":null,"manifest_position":97035,"manifest_sha256":null,"split":"11-of-16"}},"parents":["commit:github.com/microsoft/sql-server-samples@d729518369f44543cf5f4833c54dde9a99731dec__download_changed_file_contents_1a6c0e9d8d3b__render_commit_patches_30db9af2efd4"],"payload":{"changed_files":[{"before_content":"/*\nTo install the pretrained model in SQL Server, open an elevated CMD promtp:\n1. Navigate to the SQL Server installation path: \nC:\\<SQL SERVER Installation path>\\Microsoft SQL Server\\140\\Setup Bootstrap\\SQL2017\\x64\n2. Run the following command: \nRSetup.exe /install /component MLM /<version>/language 1033 /destdir <SQL_DB_instance_folder>\\PYTHON_SERVICES\\Lib\\site-packages\\microsoftml\\mxLibs\nExample:\nRSetup.exe /install /component MLM /version 9.2.0.24 /language 1033 /destdir \"C:\\Program Files\\Microsoft SQL Server\\MSSQL14.MSSQLSERVER\\PYTHON_SERVICES\\Lib\\site-packages\\microsoftml\\mxLibs\"\nThe models will be downloaded and extracted.\n*/\n\n\nUSE [tpcxbb_1gb]\nGO\n\n--******************************************************************************************************************\n-- STEP 1 Stored procedure that uses a pretrained model to determine sentiment of a text, such as a product review\n--******************************************************************************************************************\nCREATE OR ALTER PROCEDURE [dbo].[get_review_sentiment]\nAS\nBEGIN\n\tDECLARE\t@script nvarchar(max);\n\t\n\t--The Python script we want to execute\n\tSET @script = N'\nfrom microsoftml import rx_featurize, get_sentiment\n\n# Get the sentiment scores\nsentiment_scores = rx_featurize(data=reviews, ml_transforms=[get_sentiment(cols=dict(scores=\"review\"))])\n\n# Lets translate the score to something more meaningful\nsentiment_scores[\"Sentiment\"] = sentiment_scores.scores.apply(lambda score: \"Positive\" if score > 0.6 else \"Negative\")\n';\n\t\n\tEXECUTE sp_execute_external_script\n\t\t\t\t@language = N'Python'\n\t\t\t\t, @script = @script\n\t\t\t\t, @input_data_1 = N'SELECT CAST(pr_review_content AS NVARCHAR(4000)) AS review FROM product_reviews'\n\t\t\t\t, @input_data_1_name = N'reviews'\n\t\t\t\t, @output_data_1_name = N'sentiment_scores'\n\t\t\t\tWITH RESULT SETS ((\"Review\" NVARCHAR(MAX),\"Score\" FLOAT, \"Sentiment\" NVARCHAR(30)));\t\t\t\n\nEND\n\t\t\t\t \nGO\n\n--******************************************************************************************************************\n-- STEP 2 Execute the stored procedure\n--******************************************************************************************************************\nEXECUTE [dbo].[get_review_sentiment];\nGO\n","before_content_lossy":false,"new_mode":"100644","new_oid":"a3ef4a4ba1a6a72783aaac03af1ac8f8907b8707","numstat":{"added":1,"deleted":0},"old_mode":"100644","old_oid":"b9372fc89baadbf188d04236048a31bc814937ac","path":"samples/features/machine-learning-services/python/sentiment-analysis/product-review-pretrained-model-sentiment-analysis.sql","path_bytes_base64":null,"path_lossy":false,"status":"M","unified_patch":"diff --git a/samples/features/machine-learning-services/python/sentiment-analysis/product-review-pretrained-model-sentiment-analysis.sql b/samples/features/machine-learning-services/python/sentiment-analysis/product-review-pretrained-model-sentiment-analysis.sql\nindex b9372fc89baadbf188d04236048a31bc814937ac..a3ef4a4ba1a6a72783aaac03af1ac8f8907b8707 100644\n--- a/samples/features/machine-learning-services/python/sentiment-analysis/product-review-pretrained-model-sentiment-analysis.sql\n+++ b/samples/features/machine-learning-services/python/sentiment-analysis/product-review-pretrained-model-sentiment-analysis.sql\n@@ -7,6 +7,7 @@ RSetup.exe /install /component MLM /<version>/language 1033 /destdir <SQL_DB_ins\n Example:\n RSetup.exe /install /component MLM /version 9.2.0.24 /language 1033 /destdir \"C:\\Program Files\\Microsoft SQL Server\\MSSQL14.MSSQLSERVER\\PYTHON_SERVICES\\Lib\\site-packages\\microsoftml\\mxLibs\"\n The models will be downloaded and extracted.\n+The database used for this sample can be downloaded here: https://sqlchoice.blob.core.windows.net/sqlchoice/static/tpcxbb_1gb.bak\n */\n \n \n","unified_patch_lossy":false},{"before_content":"USE [tpcxbb_1gb]\nGO\n\n--**************************************************************\n-- STEP 1 Create a table for storing the machine learning model\n--**************************************************************\nDROP TABLE IF EXISTS [dbo].[models]\nGO\nCREATE TABLE [dbo].[models](\n\t[language] [varchar](30) NOT NULL,\n\t[model_name] [varchar](30) NOT NULL,\n\t[model] [varbinary](max) NOT NULL,\n\t[create_time] [datetime2](7) NULL DEFAULT (sysdatetime()),\n\t[created_by] [nvarchar](500) NULL DEFAULT (suser_sname()),\n\tPRIMARY KEY CLUSTERED \n\t(\n\t[language],\n\t[model_name]\n\t)\n)\nGO\n\n--*************************************************************************************************************\n-- STEP 2 Look at the dataset we will use in this sample\n-- Tag is a label indicating the sentiment of a review. These are actual values we will use to train the model\n-- For training purposes, we will use 90% percent of the data.\n-- For testing / scoring purposes, we will use 10% percent of the data.\n--*************************************************************************************************************\nCREATE OR ALTER VIEW product_reviews_training_data\nAS\nSELECT TOP(CAST( ( SELECT COUNT(*) FROM product_reviews)*.9 AS INT))\n\t\tCAST(pr_review_content AS NVARCHAR(4000)) AS pr_review_content,\n\t\tCASE \n\t\t\tWHEN pr_review_rating <3 THEN 1 \n\t\t\tWHEN pr_review_rating =3 THEN 2 \n\t\t\tELSE 3 \n\t\tEND AS tag \nFROM product_reviews;\nGO\n\nCREATE OR ALTER VIEW product_reviews_test_data\nAS\nSELECT TOP(CAST( ( SELECT COUNT(*) FROM product_reviews)*.1 AS INT))\n\t\tCAST(pr_review_content AS NVARCHAR(4000)) AS pr_review_content,\n\t\tCASE \n\t\t\tWHEN pr_review_rating <3 THEN 1 \n\t\t\tWHEN pr_review_rating =3 THEN 2 \n\t\t\tELSE 3 \n\t\tEND AS tag \nFROM product_reviews;\nGO\n\n-- Look at the dataset we will use in this sample\nSELECT TOP(100) * FROM product_reviews_training_data;\nGO\n\n--***************************************************************************************************\n-- STEP 3 Create a stored procedure for training a\n-- text classifier model for product review sentiment classification (Positive, Negative, Neutral)\n-- 1 = Negative, 2 = Neutral, 3 = Positive\n--***************************************************************************************************\nCREATE OR ALTER PROCEDURE [dbo].[create_text_classification_model]\nAS\nBEGIN\n\tDECLARE\t @model varbinary(max)\n\t\t\t, @train_script nvarchar(max);\n\t\n--The Python script we want to execute\n\tSET @train_script = N'\n##Import necessary packages\nfrom microsoftml import rx_logistic_regression,featurize_text, n_gram\nimport pickle\n\n## Defining the tag column as a categorical type\ntraining_data[\"tag\"] = training_data[\"tag\"].astype(\"category\")\n\n## Create a machine learning model for multiclass text classification. \n## We are using a text featurizer function to split the text in features of 2-word chunks\nmodel = rx_logistic_regression(formula = \"tag ~ features\", data = training_data, method = \"multiClass\", ml_transforms=[\n featurize_text(language=\"English\",\n cols=dict(features=\"pr_review_content\"),\n word_feature_extractor=n_gram(2, weighting=\"TfIdf\"))])\n\n## Serialize the model so that we can store it in a table\nmodelbin = pickle.dumps(model)\n';\n\t\n\tEXECUTE sp_execute_external_script\n\t\t\t\t\t\t@language = N'Python'\n\t\t\t\t\t , @script = @train_script\n\t\t\t\t\t , @input_data_1 = N'SELECT * FROM product_reviews_training_data'\n\t\t\t\t\t , @input_data_1_name = N'training_data'\n\t\t\t\t\t , @params = N'@modelbin varbinary(max) OUTPUT' \n\t\t\t\t\t , @modelbin = @model OUTPUT;\n\n\t--Save model to DB Table\t\t\t\t \n\tDELETE FROM dbo.models WHERE model_name = 'rx_logistic_regression' and language = 'Python';\n\tINSERT INTO dbo.models (language, model_name, model) VALUES('Python', 'rx_logistic_regression', @model);\nEND;\nGO\n\n--***************************************************************************************************\n-- STEP 4 Execute the stored procedure that creates and saves the machine learning model in a table\n--***************************************************************************************************\n\nEXECUTE [dbo].[create_text_classification_model];\n--Take a look at the model object saved in the model table\nSELECT * FROM dbo.models;\nGO\n\n--******************************************************************************************************************\n-- STEP 5 --Stored procedure that uses the model we just created to predict/classify the sentiment of product reviews\n--******************************************************************************************************************\nCREATE OR ALTER PROCEDURE [dbo].[predict_review_sentiment]\nAS\nBEGIN\n\t-- text classifier for online review sentiment classification (Positive, Negative, Neutral)\n\tDECLARE\t\n\t\t\t @model_bin varbinary(max)\n\t\t\t, @prediction_script nvarchar(max);\n\t\n\t-- Select the model binary object from the model table\n\tSET @model_bin = (select model from dbo.models WHERE model_name = 'rx_logistic_regression' and language = 'Python');\n\t\n\n\t--The Python script we want to execute\n\tSET @prediction_script = N'\nfrom microsoftml import rx_predict\nfrom revoscalepy import rx_data_step \nimport pickle\n\n## The input data from the query in @input_data_1 is populated in test_data\n## We are selecting 10% of the entire dataset for testing the model\n\n## Unserialize the model\nmodel = pickle.loads(model_bin)\n\n## Use the rx_logistic_regression model \npredictions = rx_predict(model = model, data = test_data, extra_vars_to_write = [\"tag\", \"pr_review_content\"], overwrite = True)\n\n## Converting to output data set\nresult = rx_data_step(predictions)\n';\n\t\n\tEXECUTE sp_execute_external_script\n\t\t\t\t@language = N'Python'\n\t\t\t\t, @script = @prediction_script\n\t\t\t\t, @input_data_1 = N'SELECT * FROM product_reviews_test_data'\n\t\t\t\t, @input_data_1_name = N'test_data'\n\t\t\t\t, @output_data_1_name = N'result'\n\t\t\t\t, @params = N'@model_bin varbinary(max)'\n\t\t\t\t, @model_bin = @model_bin\n\t\tWITH RESULT SETS ((\"Review\" NVARCHAR(MAX),\"Tag\" FLOAT, \"Predicted_Score_Negative\" FLOAT, \"Predicted_Score_Neutral\" FLOAT, \"Predicted_Score_Positive\" FLOAT));\t\t\t\nEND\nGO\n\n\n--***************************************************************************************************\n-- STEP 6 Execute the multi class prediction using the model we trained earlier\n--***************************************************************************************************\nEXECUTE [dbo].[predict_review_sentiment] \nGO\n\n\n\n\n\t","before_content_lossy":false,"new_mode":"100644","new_oid":"4ddc531be3ed6d0975bae44477f67842a2038591","numstat":{"added":1,"deleted":0},"old_mode":"100644","old_oid":"ca4452a0d0d86120b94d50b7dee1987187e3d86e","path":"samples/features/machine-learning-services/python/sentiment-analysis/product-review-text-classification.sql","path_bytes_base64":null,"path_lossy":false,"status":"M","unified_patch":"diff --git a/samples/features/machine-learning-services/python/sentiment-analysis/product-review-text-classification.sql b/samples/features/machine-learning-services/python/sentiment-analysis/product-review-text-classification.sql\nindex ca4452a0d0d86120b94d50b7dee1987187e3d86e..4ddc531be3ed6d0975bae44477f67842a2038591 100644\n--- a/samples/features/machine-learning-services/python/sentiment-analysis/product-review-text-classification.sql\n+++ b/samples/features/machine-learning-services/python/sentiment-analysis/product-review-text-classification.sql\n@@ -1,3 +1,4 @@\n+--The database used for this sample can be downloaded here: https://sqlchoice.blob.core.windows.net/sqlchoice/static/tpcxbb_1gb.bak\n USE [tpcxbb_1gb]\n GO\n \n","unified_patch_lossy":false}],"message":"Added link to sample DB\n","message_lossy":false},"provenance":{"clone_url":"https://github.com/microsoft/sql-server-samples","commit_oid":"d729518369f44543cf5f4833c54dde9a99731dec","commits_ago_from_head":2884,"content_sha256":"8d473adfb477d0963b69349e55f2efb2f1aae2db660cae586093d366fdd6b836","manifest_sha256":null,"parent_oid":"059bbee1f866d9cccad00574faa877df235bb1ab","repository_id":"github.com/microsoft/sql-server-samples","shape":"commit"},"schema_version":"locus.item/v1"}
4
+ {"annotations":{"commit_quality_band":"07","commit_quality_score":{"commit_score":2,"deductions":[],"repo_score":2,"repo_score_components":{"dependents_reach":0,"gitstar_rank_present":2,"gitstar_rank_top_1000":0,"route_family_breadth":0,"route_language_top10":0},"rubric_version":2,"tier":7},"conventional_commit_type":{"breaking":false,"has_body":false,"issue_references":[],"message_words":7,"scope":null,"subject_length":45,"trailer_names":[],"type":null},"patch_statistics":{"added_lines":276,"context_bytes":0,"deleted_lines":0,"files_changed":3,"hunk_count":3,"patch_bytes":12874,"patch_sha256":"4c354c79e3be75fb375e06c9accb2529e5b98fd0ea024d1ace3f49d373ce2803"},"possible_ai_authorship":{"matched":[],"pattern_version":1,"signal":"no_named_signal_detected"},"programming_languages":{"files":[{"language":"sql","path":"samples/features/machine-learning-services/python/sentiment-analysis/pretrainedmodel_sentiment_analysis.sql","purpose":"source"},{"language":"sql","path":"samples/features/machine-learning-services/python/sentiment-analysis/product-review-pretrained-model-sentiment-analysis.sql","purpose":"source"},{"language":"sql","path":"samples/features/machine-learning-services/python/sentiment-analysis/product-review-text-classification.sql","purpose":"source"}],"primary_language":"sql"},"quality_band":"07","tests_touched":{"source_files_also_touched":true,"test_files":[],"touched":false},"verification_state":"parent_reconstructed"},"id":"commit-doc:github.com/microsoft/sql-server-samples@059bbee1f866d9cccad00574faa877df235bb1ab","meta":{"change_summary":{"before_state_bytes":0,"coverage":"all_files_of_the_commit_seen","files_in_original_commit":3,"files_kept":3,"patch_bytes":12874},"commit_oid":"059bbee1f866d9cccad00574faa877df235bb1ab","identity":{"author_email":"negust@microsoft.com","author_name":"nelgson","authored_at":"2017-10-30T21:08:01-07:00","commit_oid":"059bbee1f866d9cccad00574faa877df235bb1ab","commits_ago_from_head":2885,"committed_at":"2017-10-30T21:08:01-07:00","committer_email":"negust@microsoft.com","committer_name":"nelgson","parent_oid":"21a56019b33e86659f1e7905352c4058afea3e8b","tree_oid":"b52e744b5725143f2a2b2ae7df0c35f115d48d61"},"pipeline_log":[],"proof":{"replay_audit":{"failed_paths":[],"outcome":"not_sampled","sampled":false},"verification_state":"parent_reconstructed"},"repository":{"default_branch":"master","history_collected":{"commits_read":4110,"commits_skipped_parent_beyond_cutoff":null,"merge_commits_skipped":null,"newest_commit":"1ab31bc560415b570d57bb5ff9896f4698891321","oldest_commit":"0cd204129c9b9674c31837bf857059be782bbdeb"},"recorded_head_commit":"1ab31bc560415b570d57bb5ff9896f4698891321","repository_id":"github.com/microsoft/sql-server-samples","snapshot_check":"matches_recorded_head"},"repository_id":"github.com/microsoft/sql-server-samples","shape":"commit","source":{"discovery_routes":null,"manifest_position":97035,"manifest_sha256":null,"split":"11-of-16"}},"parents":["commit:github.com/microsoft/sql-server-samples@059bbee1f866d9cccad00574faa877df235bb1ab__download_changed_file_contents_907588aab810__render_commit_patches_7c4b702e1181"],"payload":{"changed_files":[{"before_content":null,"before_content_lossy":false,"new_mode":"100644","new_oid":"53187f211696840e31d09c9aa576d3fc83556035","numstat":{"added":58,"deleted":0},"old_mode":"000000","old_oid":"0000000000000000000000000000000000000000","path":"samples/features/machine-learning-services/python/sentiment-analysis/pretrainedmodel_sentiment_analysis.sql","path_bytes_base64":null,"path_lossy":false,"status":"A","unified_patch":"diff --git a/samples/features/machine-learning-services/python/sentiment-analysis/pretrainedmodel_sentiment_analysis.sql b/samples/features/machine-learning-services/python/sentiment-analysis/pretrainedmodel_sentiment_analysis.sql\nnew file mode 100644\nindex 0000000000000000000000000000000000000000..53187f211696840e31d09c9aa576d3fc83556035\n--- /dev/null\n+++ b/samples/features/machine-learning-services/python/sentiment-analysis/pretrainedmodel_sentiment_analysis.sql\n@@ -0,0 +1,58 @@\n+/*\n+To install the pretrained model in SQL Server, open an elevated CMD promtp:\n+1. Navigate to the SQL Server installation path: \n+C:\\<SQL SERVER Installation path>\\Microsoft SQL Server\\140\\Setup Bootstrap\\SQL2017\\x64\n+2. Run the following command: \n+RSetup.exe /install /component MLM /<version>/language 1033 /destdir <SQL_DB_instance_folder>\\PYTHON_SERVICES\\Lib\\site-packages\\microsoftml\\mxLibs\n+Example:\n+RSetup.exe /install /component MLM /version 9.2.0.24 /language 1033 /destdir \"C:\\Program Files\\Microsoft SQL Server\\MSSQL14.MSSQLSERVER\\PYTHON_SERVICES\\Lib\\site-packages\\microsoftml\\mxLibs\"\n+The models will be downloaded and extracted.\n+*/\n+\n+\n+USE [tpcxbb_1gb]\n+GO\n+\n+--******************************************************************************************************************\n+-- STEP 1 Stored procedure that uses a pretrained model to determine sentiment of a text, such as a product review\n+--******************************************************************************************************************\n+CREATE OR ALTER PROCEDURE [dbo].[get_sentiment] \n+(@text NVARCHAR(MAX))\n+AS\n+BEGIN\n+\tDECLARE\t@script nvarchar(max);\n+\t\n+\t--The Python script we want to execute\n+\tSET @script = N'\n+import pandas as p\n+from microsoftml import rx_featurize, get_sentiment\n+\n+analyze_this = text\n+\n+# Create the data\n+text_to_analyze = p.DataFrame(data=dict(Text=[analyze_this]))\n+\n+# Get the sentiment scores\n+sentiment_scores = rx_featurize(data=text_to_analyze,ml_transforms=[get_sentiment(cols=dict(scores=\"Text\"))])\n+\n+# Lets translate the score to something more meaningful\n+sentiment_scores[\"Sentiment\"] = sentiment_scores.scores.apply(lambda score: \"Positive\" if score > 0.6 else \"Negative\")\n+';\n+\t\n+\tEXECUTE sp_execute_external_script\n+\t\t\t\t@language = N'Python'\n+\t\t\t\t, @script = @script\n+\t\t\t\t, @output_data_1_name = N'sentiment_scores'\n+\t\t\t\t, @params = N'@text nvarchar(max)'\n+\t\t\t\t, @text = @text\n+\t\t\t\tWITH RESULT SETS ((\"Text\" NVARCHAR(MAX),\"Score\" FLOAT, \"Sentiment\" NVARCHAR(30)));\t\t\t\n+\n+END\n+\t\t\t\t \n+GO\n+\n+--******************************************************************************************************************\n+-- STEP 2 Execute the stored procedure to get sentiment of your own text\n+--******************************************************************************************************************\n+EXECUTE [dbo].[get_sentiment] N'ENTER YOUR OWN TEXT HERE';\n+GO\n","unified_patch_lossy":false},{"before_content":null,"before_content_lossy":false,"new_mode":"100644","new_oid":"b9372fc89baadbf188d04236048a31bc814937ac","numstat":{"added":51,"deleted":0},"old_mode":"000000","old_oid":"0000000000000000000000000000000000000000","path":"samples/features/machine-learning-services/python/sentiment-analysis/product-review-pretrained-model-sentiment-analysis.sql","path_bytes_base64":null,"path_lossy":false,"status":"A","unified_patch":"diff --git a/samples/features/machine-learning-services/python/sentiment-analysis/product-review-pretrained-model-sentiment-analysis.sql b/samples/features/machine-learning-services/python/sentiment-analysis/product-review-pretrained-model-sentiment-analysis.sql\nnew file mode 100644\nindex 0000000000000000000000000000000000000000..b9372fc89baadbf188d04236048a31bc814937ac\n--- /dev/null\n+++ b/samples/features/machine-learning-services/python/sentiment-analysis/product-review-pretrained-model-sentiment-analysis.sql\n@@ -0,0 +1,51 @@\n+/*\n+To install the pretrained model in SQL Server, open an elevated CMD promtp:\n+1. Navigate to the SQL Server installation path: \n+C:\\<SQL SERVER Installation path>\\Microsoft SQL Server\\140\\Setup Bootstrap\\SQL2017\\x64\n+2. Run the following command: \n+RSetup.exe /install /component MLM /<version>/language 1033 /destdir <SQL_DB_instance_folder>\\PYTHON_SERVICES\\Lib\\site-packages\\microsoftml\\mxLibs\n+Example:\n+RSetup.exe /install /component MLM /version 9.2.0.24 /language 1033 /destdir \"C:\\Program Files\\Microsoft SQL Server\\MSSQL14.MSSQLSERVER\\PYTHON_SERVICES\\Lib\\site-packages\\microsoftml\\mxLibs\"\n+The models will be downloaded and extracted.\n+*/\n+\n+\n+USE [tpcxbb_1gb]\n+GO\n+\n+--******************************************************************************************************************\n+-- STEP 1 Stored procedure that uses a pretrained model to determine sentiment of a text, such as a product review\n+--******************************************************************************************************************\n+CREATE OR ALTER PROCEDURE [dbo].[get_review_sentiment]\n+AS\n+BEGIN\n+\tDECLARE\t@script nvarchar(max);\n+\t\n+\t--The Python script we want to execute\n+\tSET @script = N'\n+from microsoftml import rx_featurize, get_sentiment\n+\n+# Get the sentiment scores\n+sentiment_scores = rx_featurize(data=reviews, ml_transforms=[get_sentiment(cols=dict(scores=\"review\"))])\n+\n+# Lets translate the score to something more meaningful\n+sentiment_scores[\"Sentiment\"] = sentiment_scores.scores.apply(lambda score: \"Positive\" if score > 0.6 else \"Negative\")\n+';\n+\t\n+\tEXECUTE sp_execute_external_script\n+\t\t\t\t@language = N'Python'\n+\t\t\t\t, @script = @script\n+\t\t\t\t, @input_data_1 = N'SELECT CAST(pr_review_content AS NVARCHAR(4000)) AS review FROM product_reviews'\n+\t\t\t\t, @input_data_1_name = N'reviews'\n+\t\t\t\t, @output_data_1_name = N'sentiment_scores'\n+\t\t\t\tWITH RESULT SETS ((\"Review\" NVARCHAR(MAX),\"Score\" FLOAT, \"Sentiment\" NVARCHAR(30)));\t\t\t\n+\n+END\n+\t\t\t\t \n+GO\n+\n+--******************************************************************************************************************\n+-- STEP 2 Execute the stored procedure\n+--******************************************************************************************************************\n+EXECUTE [dbo].[get_review_sentiment];\n+GO\n","unified_patch_lossy":false},{"before_content":null,"before_content_lossy":false,"new_mode":"100644","new_oid":"ca4452a0d0d86120b94d50b7dee1987187e3d86e","numstat":{"added":167,"deleted":0},"old_mode":"000000","old_oid":"0000000000000000000000000000000000000000","path":"samples/features/machine-learning-services/python/sentiment-analysis/product-review-text-classification.sql","path_bytes_base64":null,"path_lossy":false,"status":"A","unified_patch":"diff --git a/samples/features/machine-learning-services/python/sentiment-analysis/product-review-text-classification.sql b/samples/features/machine-learning-services/python/sentiment-analysis/product-review-text-classification.sql\nnew file mode 100644\nindex 0000000000000000000000000000000000000000..ca4452a0d0d86120b94d50b7dee1987187e3d86e\n--- /dev/null\n+++ b/samples/features/machine-learning-services/python/sentiment-analysis/product-review-text-classification.sql\n@@ -0,0 +1,167 @@\n+USE [tpcxbb_1gb]\n+GO\n+\n+--**************************************************************\n+-- STEP 1 Create a table for storing the machine learning model\n+--**************************************************************\n+DROP TABLE IF EXISTS [dbo].[models]\n+GO\n+CREATE TABLE [dbo].[models](\n+\t[language] [varchar](30) NOT NULL,\n+\t[model_name] [varchar](30) NOT NULL,\n+\t[model] [varbinary](max) NOT NULL,\n+\t[create_time] [datetime2](7) NULL DEFAULT (sysdatetime()),\n+\t[created_by] [nvarchar](500) NULL DEFAULT (suser_sname()),\n+\tPRIMARY KEY CLUSTERED \n+\t(\n+\t[language],\n+\t[model_name]\n+\t)\n+)\n+GO\n+\n+--*************************************************************************************************************\n+-- STEP 2 Look at the dataset we will use in this sample\n+-- Tag is a label indicating the sentiment of a review. These are actual values we will use to train the model\n+-- For training purposes, we will use 90% percent of the data.\n+-- For testing / scoring purposes, we will use 10% percent of the data.\n+--*************************************************************************************************************\n+CREATE OR ALTER VIEW product_reviews_training_data\n+AS\n+SELECT TOP(CAST( ( SELECT COUNT(*) FROM product_reviews)*.9 AS INT))\n+\t\tCAST(pr_review_content AS NVARCHAR(4000)) AS pr_review_content,\n+\t\tCASE \n+\t\t\tWHEN pr_review_rating <3 THEN 1 \n+\t\t\tWHEN pr_review_rating =3 THEN 2 \n+\t\t\tELSE 3 \n+\t\tEND AS tag \n+FROM product_reviews;\n+GO\n+\n+CREATE OR ALTER VIEW product_reviews_test_data\n+AS\n+SELECT TOP(CAST( ( SELECT COUNT(*) FROM product_reviews)*.1 AS INT))\n+\t\tCAST(pr_review_content AS NVARCHAR(4000)) AS pr_review_content,\n+\t\tCASE \n+\t\t\tWHEN pr_review_rating <3 THEN 1 \n+\t\t\tWHEN pr_review_rating =3 THEN 2 \n+\t\t\tELSE 3 \n+\t\tEND AS tag \n+FROM product_reviews;\n+GO\n+\n+-- Look at the dataset we will use in this sample\n+SELECT TOP(100) * FROM product_reviews_training_data;\n+GO\n+\n+--***************************************************************************************************\n+-- STEP 3 Create a stored procedure for training a\n+-- text classifier model for product review sentiment classification (Positive, Negative, Neutral)\n+-- 1 = Negative, 2 = Neutral, 3 = Positive\n+--***************************************************************************************************\n+CREATE OR ALTER PROCEDURE [dbo].[create_text_classification_model]\n+AS\n+BEGIN\n+\tDECLARE\t @model varbinary(max)\n+\t\t\t, @train_script nvarchar(max);\n+\t\n+--The Python script we want to execute\n+\tSET @train_script = N'\n+##Import necessary packages\n+from microsoftml import rx_logistic_regression,featurize_text, n_gram\n+import pickle\n+\n+## Defining the tag column as a categorical type\n+training_data[\"tag\"] = training_data[\"tag\"].astype(\"category\")\n+\n+## Create a machine learning model for multiclass text classification. \n+## We are using a text featurizer function to split the text in features of 2-word chunks\n+model = rx_logistic_regression(formula = \"tag ~ features\", data = training_data, method = \"multiClass\", ml_transforms=[\n+ featurize_text(language=\"English\",\n+ cols=dict(features=\"pr_review_content\"),\n+ word_feature_extractor=n_gram(2, weighting=\"TfIdf\"))])\n+\n+## Serialize the model so that we can store it in a table\n+modelbin = pickle.dumps(model)\n+';\n+\t\n+\tEXECUTE sp_execute_external_script\n+\t\t\t\t\t\t@language = N'Python'\n+\t\t\t\t\t , @script = @train_script\n+\t\t\t\t\t , @input_data_1 = N'SELECT * FROM product_reviews_training_data'\n+\t\t\t\t\t , @input_data_1_name = N'training_data'\n+\t\t\t\t\t , @params = N'@modelbin varbinary(max) OUTPUT' \n+\t\t\t\t\t , @modelbin = @model OUTPUT;\n+\n+\t--Save model to DB Table\t\t\t\t \n+\tDELETE FROM dbo.models WHERE model_name = 'rx_logistic_regression' and language = 'Python';\n+\tINSERT INTO dbo.models (language, model_name, model) VALUES('Python', 'rx_logistic_regression', @model);\n+END;\n+GO\n+\n+--***************************************************************************************************\n+-- STEP 4 Execute the stored procedure that creates and saves the machine learning model in a table\n+--***************************************************************************************************\n+\n+EXECUTE [dbo].[create_text_classification_model];\n+--Take a look at the model object saved in the model table\n+SELECT * FROM dbo.models;\n+GO\n+\n+--******************************************************************************************************************\n+-- STEP 5 --Stored procedure that uses the model we just created to predict/classify the sentiment of product reviews\n+--******************************************************************************************************************\n+CREATE OR ALTER PROCEDURE [dbo].[predict_review_sentiment]\n+AS\n+BEGIN\n+\t-- text classifier for online review sentiment classification (Positive, Negative, Neutral)\n+\tDECLARE\t\n+\t\t\t @model_bin varbinary(max)\n+\t\t\t, @prediction_script nvarchar(max);\n+\t\n+\t-- Select the model binary object from the model table\n+\tSET @model_bin = (select model from dbo.models WHERE model_name = 'rx_logistic_regression' and language = 'Python');\n+\t\n+\n+\t--The Python script we want to execute\n+\tSET @prediction_script = N'\n+from microsoftml import rx_predict\n+from revoscalepy import rx_data_step \n+import pickle\n+\n+## The input data from the query in @input_data_1 is populated in test_data\n+## We are selecting 10% of the entire dataset for testing the model\n+\n+## Unserialize the model\n+model = pickle.loads(model_bin)\n+\n+## Use the rx_logistic_regression model \n+predictions = rx_predict(model = model, data = test_data, extra_vars_to_write = [\"tag\", \"pr_review_content\"], overwrite = True)\n+\n+## Converting to output data set\n+result = rx_data_step(predictions)\n+';\n+\t\n+\tEXECUTE sp_execute_external_script\n+\t\t\t\t@language = N'Python'\n+\t\t\t\t, @script = @prediction_script\n+\t\t\t\t, @input_data_1 = N'SELECT * FROM product_reviews_test_data'\n+\t\t\t\t, @input_data_1_name = N'test_data'\n+\t\t\t\t, @output_data_1_name = N'result'\n+\t\t\t\t, @params = N'@model_bin varbinary(max)'\n+\t\t\t\t, @model_bin = @model_bin\n+\t\tWITH RESULT SETS ((\"Review\" NVARCHAR(MAX),\"Tag\" FLOAT, \"Predicted_Score_Negative\" FLOAT, \"Predicted_Score_Neutral\" FLOAT, \"Predicted_Score_Positive\" FLOAT));\t\t\t\n+END\n+GO\n+\n+\n+--***************************************************************************************************\n+-- STEP 6 Execute the multi class prediction using the model we trained earlier\n+--***************************************************************************************************\n+EXECUTE [dbo].[predict_review_sentiment] \n+GO\n+\n+\n+\n+\n+\t\n\\n","unified_patch_lossy":false}],"message":"Added sentiment analysis script - ML services\n","message_lossy":false},"provenance":{"clone_url":"https://github.com/microsoft/sql-server-samples","commit_oid":"059bbee1f866d9cccad00574faa877df235bb1ab","commits_ago_from_head":2885,"content_sha256":"236142a4da3c6de80ca70729b1dba02cb17bd5db9b923b907bf4b63f467459da","manifest_sha256":null,"parent_oid":"21a56019b33e86659f1e7905352c4058afea3e8b","repository_id":"github.com/microsoft/sql-server-samples","shape":"commit"},"schema_version":"locus.item/v1"}