Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

NLP Sentiment tool in other languages

jcalvo92
7 - Meteor

Hi everyone

 

I was following the Comparing Sentiment Analysis Algorithms article, but when trying to use the StandfordCoreNLP Sentiment tool I was getting the error "The external program "java" returned an error code: 2", just like in this post, being unable to run Java using the RunCommand.

 

The solution, posted here, worked fine, being able to solve the problem by wraping the java command in a cmd shell. 

 

However, I am unable to get the CoreNLP running in other languages,as explained here. Any idea on how to modify the macro to achieve this? I have been toying with the configuration of some Formula tools but I am back to Java errors.

 

Cheers,

Javi Calvo 

 

 

 

5 REPLIES 5
BrandonB
Alteryx
Alteryx

Hi @jcalvo92 

 

It looks like quite a bit of work needs to be done to get that tool to run with other languages based on the dependencies listed. One alternative would be to run your text through a translation API as part of your workflow to then be run through an English sentiment analysis process. That way you could run the tool as is.

jcalvo92
7 - Meteor

Hi @BrandonB

 

That’s actually a solid alternative, but it moves the problem to how to translate texts in Alteryx. I am only able to find solutions that use the Cognitive Services Text Translation macro. This uses the same Microsoft paid services than the Cognitive Services Text Analytics macro, which already provides sentiment analysis in multiple languages at the same price.

 

So instead of paying for a translation, you can pay directly for a sentiment analysis in your language of choice.

 

The "Comparing Sentiment Analysis Algorithms" article that I mentioned explored different open source solutions, but all of them are in English only, or difficult to adapt to Alteryx.

 

Do you know an open source solution to translate texts in Alteryx? That would solve the problem.

 

Thank you for your feedback

BrandonB
Alteryx
Alteryx

I haven't used it yet myself, but there are quite a few free Python libraries that offer free text translation like the following: 

https://pypi.org/project/googletrans/

 

 

jcalvo92
7 - Meteor

Thanks, will have a look at it

jcalvo92
7 - Meteor

Just to update this topic...

 

I tried translating to English and then use the Stanford core. Also tried other packages such as TextBlob & Vader. At the end, I got the best results with a package called 'Spanish Sentiment Analysis', with everything in Spanish from scratch

 

Attached is a macro that gets a text field and returns the score 0..1

 

The second best option was translating the texts and moving to TextBlob. Here is some code for your python tool to use both TB and SpanishSA:

 

from ayx import Package
Package.installPackages(['pandas','numpy'])
from ayx import Alteryx

# TextBlob
Package.installPackages(['textblob'])

from textblob import TextBlob
from textblob.sentiments import NaiveBayesAnalyzer

def traducir(text):
    try:
        return TextBlob(text).translate(from_lang = 'es', to='en')
    except:
        return None
    
def calcular_sentimientos(textBlob):
    try:
        return textBlob.sentiment
    except:
        return None

def calcular_polaridad(textBlob):
    try:
        return textBlob.sentiment.polarity
    except:
        return None
    
def calcular_subjetividad(textBlob):
    try:
        return textBlob.sentiment.subjectivity
    except:
        return None

# Spanish Sentiment Analysis
Package.installPackages(['spanish_sentiment_analysis'])
# Necesita permisos y conex abierta.
# Necesita Microsoft Visual C++ Build Tools 

from classifier import *
clf = SentimentClassifier()

def score_spa(text):
    try:
        return clf.predict(text)
    except:
        return None

# Procesar todas las líneas
texto = Alteryx.read("#1")
texto2 = texto
texto2['salida'] = texto['entrada'].apply(traducir)
texto2['tb_polaridad'] = texto2['salida'].apply(calcular_polaridad)
texto2['tb_subjetividad'] = texto2['salida'].apply(calcular_subjetividad)
# Es necesario cambiar el tipo de la salida
texto2['salida'] = texto['salida'].apply(str)
texto2['spa_score'] = texto['entrada'].apply(score_spa)

# Salida
import pandas as pd
# Necesario para modificar el tipo de datos
b = pd.DataFrame(texto2)
Alteryx.write(b,1)

 

The solution is not optimal, you need to tune it to your needs, by finding specific expressions or words in your use-case and adapting the wf

 

Cheers,

Javi

 

 

Labels