Icon

01.Capturing Segments - Sentiment Predictor - Lexicon Based - Exercise

<p>This workflow preprocesses a batch of airline reviews and tags their words as positive, negative, or neutral. Next, it calculates a sentiment score based on the frequency of positive and negative words in a review, and then determines whether a review is positive or negative based on its sentiment score. At the end of the workflow, the performance of this simple, tag-based sentiment classifier is assessed.</p>

Part 3 - Workflow Invocation and Integrated Deployment

Exercise 01 Capturing Segments - Sentiment Predictor - Lexicon Based

Learning objective: In this exercise you'll use integrated deployment to capture segments of a workflow that builds a lexicon-based sentiment analysis predictor.


Workflow description: This workflow preprocesses a batch of airline reviews and tags their words as positive, negative, or neutral. Next, it calculates a sentiment score based on the frequency of positive and negative words in a review, and then determines whether a review is positive or negative based on its sentiment score. At the end of the workflow, the performance of this simple, tag-based sentiment classifier is assessed.


You'll find the instructions to the exercises in the yellow annotations.

Step 1. Capturing the data preprocessing segment of the workflow

Here the most important node is Strings to Document, which formats several string columns into a single document that can be text-mined in KNIME.

  1. Drag the Capture Workflow Start node to this part of the workflow. Connect the output of the CSV Reader node to its input port, and connect its output to the input port of the Duplicate Row Filter node.

  2. Drag the Capture Workflow End node to this part of the workflow. Connect the output of the Strings to Document node to its input port.

  3. Drag the Workflow Writer node to this part of the workflow. Connect the second output of the Capture Workflow End node to its input port. In its configuration, set "Write to" option as "Relative to" and 'Current Workflow"; "Folder" as "../Workflow Segments"; check option "Use custom workflow name"; and set "Custom Workflow Name" as "01.Captured Segment 1 Data Preparation". Click "OK" and execute this node to create a workflow segment that captures this part of the workflow.

  4. Connect the first output port of the Capture Workflow End node to the input of the following instance of the Capture Workflow Start node, already present in this workflow.


Here we read an annotated twitter dataset containing sentiments of over 14K airline reviews left by users on Twitter.

Here we capture a metanode that tags words based on their sentiment. Non-tagged words get filtered out in the end.

Step 2. Creating a shared component that counts the number of positive and negative words per document

This component encapsulates the counting of sentiment words per document (e.g., tweet), separated by class.

  1. Pressing 'Shift' and using your mouse's left-click button, select nodes starting from Bag of Words Creator all the way to the Missing Value node.

  2. Right-click and select option "Create Component" (or press Ctrl + J) and then name it Numbers of Positive and Negative Words per Tweet.

  3. OPTIONAL: Right-click the newly created component, go to option "Component" and then click option "Share...". Navigate to L3-DA Productionizing Data Apps/Part 3/Components, choosing it as the location for your component. Select option "Include input data with component" and press 'OK'.

    • Again, right-click the newly created component, go to option "Component" and then click option "Change Link Type...". Select option "Create workflow-relative link" and press 'OK'.


Calculate a Sentiment Score based on the Number of Positive and Negative Words and Classify Documents based on the Score. The sentiment score is calculated by (number of postive words - number of negative words) divided by (number of postive words + number of negative words). If the score is negative, the document is classified as negative; if the score is positive, it is classified as positive; and if it is equal to 0, it is classified as neutral.

Join the original data with data to which sentiments were predicted. This join has the goal of guaranteeing that, in the end, we still have all the documents we had in the beginning -- even if sentiments were not predicted for all of them. Documents with no sentiment words, for example, get filtered out by the predictor, but with this last join we make sure that they are still part of the output of this workflow (and they will have 'neutral' as associated sentiment class).

Scorer. Here we use the "Scorer" node to check how well our lexicon-based predictions match the annotated data. The performance is not very good because this approach is a bit too simplistic.

Scorer
Start capturingjoiningsegment intoa workflow
Capture Workflow Start
Filtered words
Bag Of Words Creator
Create id column
RowID
Convert strings to to documents
Strings to Document
Kaggle Dataset N=14640 Tweets from consumers to airlines
CSV Reader
End capturingworkflow segment
Capture Workflow End
Write captured workflow
Workflow Writer
Join Sentiment Predictions and Original Data
Table Validator
Calculate Scores
End capturingworkflow segment
Capture Workflow End
Tags to String
Start capturing word taggingsegment into a workflow
Capture Workflow Start
Duplicate Row Filter
Column Filter
Write capturedworkflow
Workflow Writer
By documents via sentiments
Pivot
Missing Value
"positive" or "negative"
Tag Words
TF absolute
TF

Nodes

Extensions

Links