amazon-web-services - 使用 AWS 进行情绪分析的最佳方法是什么?
问题描述
我对文章有 300-500 条不同的评论,我想对每一篇文章进行情绪分析,然后对所有结果进行平均。
我已经使用“无服务器”( https://www.serverless.com/ ) 框架构建了一个 REST 端点,其中包含所有评论。当用户向我的终端节点发送请求时,我想使用 AWS Comprehend: DetectSentiment 服务来分析所有评论。所以我需要将所有评论发送给它并等待回复。
到目前为止,我想出了两种不同的方法:
1. 在我的“无服务器”REST 端点中使用线程。每个线程都在调用这个函数:
def sentiment_analysis(string):
url = 'https://url_to_my_aws_sentiment_analysis_function'
x = requests.post(url, json.dumps({'Text': string}))
return x
这是我在 AWS 服务中的代码:
def lambda_handler(event, context):
client_sentiment = boto3.client('comprehend') # create a client object
text = event['Text']
response = client_sentiment.detect_sentiment(
Text=text,
LanguageCode='en'
)
return {
'statusCode': 200,
'headers': {
'Access-Control-Allow-Headers': 'Content-Type',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'OPTIONS,POST,GET'
},
'body': json.dumps('Hello from Lambda!'),
'response' : response
}
从我的 REST 端点,将一个 JSON 文件中的所有评论发送到 AWS。然后在我的lambda_handler
函数中,我将使用boto3.client('comprehend').start_sentiment_detection_job(...)
桶和所有东西来启动情绪分析的异步工作。工作完成后,我lambda_handler
将发送回一个包含分析的压缩文件。(免责声明 - 我仍然有这个选项的问题)
所以我的问题是——哪一种方法更好?如果我还没有想出另一种方法,我想知道!谢谢!
解决方案
推荐阅读
- raku - 如果路径包含非拉丁字符则出错
- javascript - 使用 CSS 或 JavaScript 关闭输入的自动更正
- javascript - 如何在 mLab 中导入和使用 firebase 导出的数据库?
- visual-studio-code - VSCode 扩展。如何在右键单击时选择树视图项
- macos - root用户不能删除文件
- android - Android 显示错误:尝试在空对象引用上调用接口方法“int java.util.List.size()”
- camera - 如何将相机输出更改为屏幕显示?
- asynchronous - c# Ftp 文件上传异步 | 同步
- google-api - 如何在没有 oAuth2.0 的情况下使用带有驱动器 API 密钥的谷歌驱动器文件列表 API?
- node.js - How to send http(s) requests with Node.js to a Node.js server hosted with LocalTunnel