Advertisement
jroakes

Nozzle BigQuery ML Sentiment

Jun 28th, 2021
1,413
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.01 KB | None | 0 0
  1. WITH
  2.  
  3. current_paas AS (
  4.     SELECT
  5.     DISTINCT(paa_text)
  6.     FROM `project.dataset.paa_text_table`  -- edit this
  7.  
  8. ),
  9.  
  10. nozzle_paa_results AS (
  11.     SELECT
  12.         DISTINCT(related_phrase) AS paa_text
  13.         FROM `nozzle.client_ranking_data.locomotive_locomotive`  -- edit this
  14.         WHERE result_type = 'PAA'
  15.         AND related_phrase IS NOT NULL
  16.         AND keyword_group = "brand" -- edit this
  17.         AND related_phrase NOT IN (SELECT paa_text FROM current_paas)
  18.         AND date(requested) > DATE_SUB(current_date(), INTERVAL 150 DAY)
  19.         ORDER BY related_phrase
  20.         LIMIT 50
  21.  
  22. ),
  23.  
  24. predictions AS (
  25.     SELECT
  26.     paa_text,
  27.     ROUND(classifier[OFFSET(1)], 3) as score
  28.     FROM ML.PREDICT(MODEL `project.bigquery_ml.sentiment`,(SELECT REGEXP_REPLACE(paa_text, '[^\\w\\s]+', '') AS text FROM nozzle_paa_results))
  29.     JOIN (SELECT paa_text, REGEXP_REPLACE(paa_text, '[^\\w\\s]+', '') AS text FROM nozzle_paa_results) USING (text)
  30.     ORDER BY score ASC
  31.        
  32.  
  33. )
  34.  
  35. SELECT * FROM predictions;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement