Comments (1)
Hi @AymenBenk
slack is a list containing a single element and hence you can't do slack.aspect.
One workaround to extract weights, scores and aspect could be as following:
# Convert slack from list to string.
slack = str(slack)
import re
# Replace suitable characters with new line characters.
wei = slack.replace(")", " \n ")
sco = slack.replace("]", " \n ")
asp = slack.replace(",", " \n ")
# Find out the weights, scores and aspect in the above 3 strings.
weights = re.findall(r"\bwei.*", wei)
scores = re.search(r"\bsco.*", sco)
scores = str(scores.group()) + "]"
aspec = re.search(r"\basp.*", asp)
print(weights)
print(scores)
print(aspec.group())
# Results are as following:
['weights=[0.28, 1.0, 0.71] ', 'weights=[0.13, 0.58, 0.58] ', 'weights=[0.25, 0.25, 0.17] ']
scores=[0.0005469012, 0.0009526044, 0.99850047 ]
aspect='mascara'
The second better approach is:
an_string = str(slack)
# Extract aspect
aspect = an_string.split('aspect=')[1].split(',')[0]
print("aspect", aspect)
# Extract scores
scores = an_string.split("scores=[")[1].split("]")[0].split(",")
scores = [float(score) for score in scores]
print("scores", scores)
# Extract weights
def extract_weights(an_string,i):
weights = an_string.split("weights=[")[i].split("]")[0].split(",")
weights = [float(weight) for weight in weights]
print(weights)
print("weights")
extract_weights(an_string,1)
extract_weights(an_string,2)
extract_weights(an_string,3)
# Results are as following:
aspect 'mascara'
scores [0.0005469007, 0.0009526035, 0.99850047]
weights
[0.28, 1.0, 0.71]
[0.13, 0.58, 0.58]
[0.25, 0.25, 0.17]
from aspect-based-sentiment-analysis.
Related Issues (20)
- Error running Pipeline with BasicReferenceRecognizer HOT 2
- Fine-tuning the model to add specific words and phrases with polarity HOT 1
- GPU usage with Large Data during prediction HOT 1
- Type mismatch error during operation on `scores` array HOT 1
- Getting Error while calling BERTClassifier HOT 4
- How to fine tune this model HOT 1
- Performs invalid character removal and whitespace cleanup on text
- Getting error from professor file! HOT 1
- Getting error with basic first code HOT 5
- numpy-1.19.5-cp37-cp37m-manylinux2010_x86_64.whl: 2 vulnerabilities (highest severity is: 5.3)
- Disabling the computation and output of Attention and Interpretation results
- Werkzeug-2.2.2-py3-none-any.whl: 4 vulnerabilities (highest severity is: 7.5)
- Question about this ABSA package integration with the 🤗Transformers pipeline
- scipy-1.7.3-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl: 2 vulnerabilities (highest severity is: 9.8) - autoclosed HOT 1
- grpcio-1.34.1-cp37-cp37m-manylinux2014_x86_64.whl: 1 vulnerabilities (highest severity is: 7.5) - autoclosed HOT 1
- urllib3-1.26.13-py2.py3-none-any.whl: 2 vulnerabilities (highest severity is: 8.1)
- transformers-4.8.2-py3-none-any.whl: 4 vulnerabilities (highest severity is: 8.8)
- certifi-2022.12.7-py3-none-any.whl: 1 vulnerabilities (highest severity is: 9.8)
- requests-2.28.1-py3-none-any.whl: 1 vulnerabilities (highest severity is: 6.1)
- Jinja2-3.1.2-py3-none-any.whl: 2 vulnerabilities (highest severity is: 6.1)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aspect-based-sentiment-analysis.