[英]Calculate AWS Comprehend Sentiment cost
I'd like to programmatically estimate the cost to call the AWS Comprehend Sentiment API.我想以编程方式估算调用 AWS Comprehend Sentiment API 的成本。 I searched SO and the AWS calculators but couldn't find a way.
我搜索了 SO 和AWS 计算器,但找不到方法。 Also, I'm sure the costs for the amount of text I'll be sending will be small but I really want to know.
此外,我确信我将发送大量文本的成本会很小,但我真的很想知道。
Based on the pricing info here I wrote the code below.根据此处的定价信息,我编写了以下代码。 Is it correct?
这是对的吗?
text = ["What a horrible rainy day today",
"What a great day today",
"This is a neutral statement"]
numChars = sum(len(i) for i in text)
#Sentiment is measured in units of 100 characters, with a 3 unit (300 character) minimum charge per request.
numUnits = int(math.ceil(numChars / 100))
# Up to 10M units
if numUnits < 10000000:
pricePerunit = 0.0001
sentimentCost = numUnits * pricePerunit
# From 10M-50M units
elif numUnits >= 10000000 and numUnits <= 50000000:
pricePerunit = 0.0001
sentimentCost = 9999999 * pricePerunit
pricePerunit = 0.00005
sentimentCost = sentimentCost + ((numUnits - 10000000) * pricePerunit)
# Over 50M units.
elif numUnits > 50000000:
pricePerunit = 0.0001
sentimentCost = 9999999 * pricePerunit
pricePerunit = 0.00005
sentimentCost = sentimentCost + (40000000 * pricePerunit)
pricePerunit = 0.000025
sentimentCost = sentimentCost + ((numUnits - 49999999) * pricePerunit)
print("\nEstimated $ charges to call AWS Comprehend Sentiment are: %0.5f\n" % sentimentCost)
No, this calculation is not correct.不,这个计算是不正确的。 Specifically:
具体来说:
math.ceil(numChars / 100)
math.ceil(numChars / 100)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.