简体   繁体   English

计算 AWS Comprehend Sentiment 成本

[英]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:具体来说:

  • you need to round up for units so use math.ceil(numChars / 100)您需要对单位进行四舍五入,因此请使用math.ceil(numChars / 100)
  • the cost/unit is different for the first 10M, the next 40M, and anything beyond 50M, and you have mistakenly assumed that all units are charged at the marginal rate.前 10M、接下来的 40M 和超过 50M 的任何单位的成本是不同的,并且您错误地假设所有单位都按边际费率收费。 Your code will calculate the cost of 10M+1 units as (10M+1) * 0.00005 when it should be 10M*0.0001 + 1*0.00005您的代码将计算 10M+1 单位的成本为 (10M+1) * 0.00005,而它应该是 10M*0.0001 + 1*0.00005
  • also, your code will crash with exactly 10000000 or 50000000 units此外,您的代码将在恰好 10000000 或 50000000 个单位时崩溃

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 数据转换-根据 aws 服务和 Pandas 中的百分比计算总成本 - data transformation-calculate total cost based on aws services and percentage in pandas 如何计算有折扣的运费 - how to calculate shipping cost with discount TextBlob如何计算情感极性? 如何使用机器学习分类器计算情感价值? - How does TextBlob calculate sentiment polarity? How can I calculate a value for sentiment with machine learning classifier? 如何使用sentiwordnet获得同义词集并计算其情感分数 - How to get synsets using sentiwordnet and calculate their sentiment score 计算圆形物体的每平方成本 - Calculate the cost per square of a circular object 如何使用我的使用量和量对成本的括号动态计算水费成本? - How do I dynamically calculate a water bill cost using my usage volume and volume-to-cost brackets? 如何获取AWS中每个IAM用户使用的资源/成本的摘要? - How to get a summary of ressources/cost used per IAM users in AWS? 初始化基本堆栈,但是我不理解错误 - initializing basic stack, but errors i do not comprehend 如何理解二叉树中的以下递归函数? - How to comprehend the following recursive function in binary tree? 无法理解来自 httpie 调用的错误 - Not able to comprehend the error from httpie call
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM