RasaHQ / carbon-bot

Apache License 2.0
42 stars 31 forks source link

Make Carbon bot use the Climatiq API #51

Closed samsucik closed 2 years ago

samsucik commented 2 years ago

The Climatiq API estimates CO2 given a distance or IATA codes. To make requests, we need an API key.

An important part of using the API is choosing the emission factors to be used. An emission factor is a coefficient used to compute the CO2 estimate from parameters like distance or flight class. Emission factors differ depending on the distance: E.g., long-haul flight planes fly higher, where the real impact of emitted CO2 is also higher. Different emission factors exist based on different methodologies, e.g. in the UK the emission factors also account for a plane's contrails, for the different greenhouse gases emitted, and upweight the estimate in a particular way for long-haul flights. Institutions in other countries produce different numbers as they use slightly different approaches.

In this PR, I chose the UK emission factors (but it's easy to switch to ones from a different source). They seem to be quite conservative, i.e. they account for emission effects that get ignored in many other emission factors. The UK factors also distinguish between domestic and international flights in a particular way that varies between countries and methodologies -- in this case, domestic means any flight within the UK, i.e. up to ~760 km.

Besides choosing the emission factors, this PR also adds the API key into the action server Docker image so that requests can be made when the action server is deployed (the actual API key is stored as a secret on the carbon-bot repo).

In terms of testing that everything works (around the API), I've checked this locally but I admit that we might want to set up a unit test for the action server.

github-actions[bot] commented 2 years ago

Intent Cross-Validation Results (5 folds)

class support f1-score confused_with
macro avg 2517 0.7392969443040304 N/A
weighted avg 2517 0.8044163022910361 N/A
faq 643 0.7808946171341925 estimate_emissions(23), inquire-ask_clarification-offsets(21)
inform 616 0.9413680781758957 faq(14), estimate_emissions(8)
affirm 255 0.8919449901768173 faq(7), express_positive-emo(5)
inquire-ask_clarification-offsets 124 0.7309236947791165 faq(22), inform_notunderstanding(4)
estimate_emissions 73 0.6071428571428571 faq(11), inquire-ask_clarification-offsets(3)
deny 69 0.7164179104477613 inform_notunderstanding(4), faq(4)
greet 63 0.8615384615384615 faq(4), thank(2)
insult 63 0.7333333333333333 faq(5), inform_notunderstanding(3)
why 59 0.7428571428571429 faq(7), inquire-ask_clarification-offsets(6)
inform_notunderstanding 58 0.4615384615384615 faq(19), deny(3)
farewell 57 0.7747747747747747 faq(7), deny(3)
thank 54 0.8928571428571429 faq(1), affirm(1)
express_positive-emo 48 0.7083333333333334 SCENARIO(2), deny(2)
vulgar 46 0.6388888888888888 faq(13), insult(7)
express_surprise 43 0.6666666666666666 faq(10), express_positive-emo(2)
express_uncertainty 43 0.7341772151898734 faq(7), affirm(2)
inquire-ask_clarification 38 0.6486486486486486 faq(8), why(3)
buy_offsets 35 0.6562500000000000 faq(8), affirm(2)
how_calculated 29 0.8363636363636363 faq(5), estimate_emissions(1)
deny_flying 28 0.5937499999999999 faq(2), deny(2)
express_negative-emo 25 0.6222222222222222 faq(3), inform_notunderstanding(2)
restart 18 0.8648648648648649 affirm(1), faq(1)
meta_inform_problem_bad-link 12 0.9600000000000001 N/A
SCENARIO 10 0.6666666666666665 faq(1), express_positive-emo(1)
help 8 0.7500000000000000 faq(1), inquire-ask_clarification-offsets(1)

Entity Cross-Validation Results (5 folds)

entity support f1-score precision recall
micro avg 926 0.79567567567567580 0.7965367965367965 0.7948164146868251
macro avg 926 0.68244951237341060 0.7548112671820053 0.6466578336409559
weighted avg 926 0.79334634425227450 0.7947887275586288 0.7948164146868251
city 384 0.87741935483870970 0.8695652173913043 0.8854166666666666
city.to 182 0.76719576719576720 0.7397959183673469 0.7967032967032966
city.from 149 0.68918918918918930 0.6938775510204082 0.6845637583892618
travel_flight_class 95 0.87830687830687850 0.8829787234042553 0.8736842105263158
iata 76 0.67605633802816900 0.7272727272727273 0.6315789473684210
iata.to 19 0.57142857142857140 0.6250000000000000 0.5263157894736842
iata.from 16 0.42857142857142855 0.5000000000000000 0.3750000000000000
number 5 0.57142857142857150 1.0000000000000000 0.4000000000000000
github-actions[bot] commented 2 years ago

Intent Cross-Validation Results (5 folds)

class support f1-score confused_with
macro avg 2517 0.72495514547066080 N/A
weighted avg 2517 0.79771993091344710 N/A
faq 643 0.77578475336322870 inquire-ask_clarification-offsets(22), inform(19)
inform 616 0.94601128122481870 faq(15), deny_flying(3)
affirm 255 0.86614173228346460 faq(13), inform(5)
inquire-ask_clarification-offsets 124 0.67432950191570880 faq(22), inquire-ask_clarification(5)
estimate_emissions 73 0.63309352517985610 faq(16), inquire-ask_clarification-offsets(7)
deny 69 0.70886075949367100 faq(5), inform_notunderstanding(3)
greet 63 0.87804878048780480 faq(6), affirm(1)
insult 63 0.70085470085470080 faq(7), vulgar(6)
why 59 0.73949579831932780 faq(9), inform_notunderstanding(2)
inform_notunderstanding 58 0.50909090909090900 faq(13), affirm(5)
farewell 57 0.80373831775700940 faq(8), inform_notunderstanding(2)
thank 54 0.89908256880733940 inform(2), faq(1)
express_positive-emo 48 0.66666666666666670 faq(6), buy_offsets(3)
vulgar 46 0.68131868131868120 insult(6), faq(5)
express_surprise 43 0.69444444444444450 faq(8), deny(4)
express_uncertainty 43 0.72000000000000000 faq(8), affirm(2)
inquire-ask_clarification 38 0.49230769230769234 faq(9), inquire-ask_clarification-offsets(8)
buy_offsets 35 0.61333333333333330 faq(8), affirm(2)
how_calculated 29 0.82142857142857150 faq(4), inquire-ask_clarification-offsets(1)
deny_flying 28 0.61224489795918370 deny(6), faq(4)
express_negative-emo 25 0.65217391304347830 inform_notunderstanding(4), insult(2)
restart 18 0.87500000000000010 inquire-ask_clarification-offsets(2), faq(1)
meta_inform_problem_bad-link 12 0.90909090909090910 faq(2)
SCENARIO 10 0.70588235294117640 inquire-ask_clarification-offsets(1), express_positive-emo(1)
help 8 0.54545454545454540 faq(5)

Entity Cross-Validation Results (5 folds)

entity support f1-score precision recall
micro avg 926 0.7853684776761701 0.7824222936763130 0.7883369330453563
macro avg 926 0.6444462040924734 0.6431215590994723 0.6463168139215003
weighted avg 926 0.7834893873662361 0.7790868440239125 0.7883369330453563
city 384 0.8490322580645162 0.8414322250639387 0.8567708333333334
city.to 182 0.7445652173913043 0.7365591397849462 0.7527472527472527
city.from 149 0.7058823529411764 0.6878980891719745 0.7248322147651006
travel_flight_class 95 0.8663101604278075 0.8804347826086957 0.8526315789473684
iata 76 0.7074829931972789 0.7323943661971831 0.6842105263157895
iata.to 19 0.7368421052631579 0.7368421052631579 0.7368421052631579
iata.from 16 0.5454545454545455 0.5294117647058824 0.5625000000000000
number 5 N/A N/A N/A
github-actions[bot] commented 2 years ago

Intent Cross-Validation Results (5 folds)

class support f1-score confused_with
macro avg 2517 0.73002298683097130 N/A
weighted avg 2517 0.79679422755261260 N/A
faq 643 0.77276326207442590 inform(29), inquire-ask_clarification-offsets(23)
inform 616 0.93537964458804520 faq(17), inform_notunderstanding(3)
affirm 255 0.88757396449704140 express_surprise(5), inform_notunderstanding(5)
inquire-ask_clarification-offsets 124 0.64777327935222680 faq(28), estimate_emissions(5)
estimate_emissions 73 0.63157894736842100 faq(10), inquire-ask_clarification-offsets(5)
deny 69 0.80821917808219180 faq(2), inform_notunderstanding(2)
insult 63 0.71428571428571430 vulgar(8), faq(3)
greet 63 0.88372093023255820 express_negative-emo(2), faq(2)
why 59 0.71999999999999990 faq(7), inquire-ask_clarification-offsets(3)
inform_notunderstanding 58 0.45669291338582674 faq(13), affirm(4)
farewell 57 0.80373831775700940 faq(3), greet(2)
thank 54 0.88288288288288290 why(1), affirm(1)
express_positive-emo 48 0.70212765957446800 express_surprise(6), affirm(2)
vulgar 46 0.66666666666666660 faq(7), insult(4)
express_uncertainty 43 0.68421052631578950 faq(5), why(4)
express_surprise 43 0.52173913043478260 faq(9), express_positive-emo(4)
inquire-ask_clarification 38 0.59154929577464790 faq(8), why(4)
buy_offsets 35 0.69841269841269850 faq(6), inquire-ask_clarification-offsets(4)
how_calculated 29 0.79245283018867930 faq(3), inform_notunderstanding(3)
deny_flying 28 0.74193548387096770 deny(2), inquire-ask_clarification-offsets(1)
express_negative-emo 25 0.62500000000000010 inform_notunderstanding(3), express_positive-emo(3)
restart 18 0.88888888888888880 farewell(1), estimate_emissions(1)
meta_inform_problem_bad-link 12 0.91666666666666660 faq(1)
SCENARIO 10 0.52631578947368420 express_positive-emo(2), estimate_emissions(1)
help 8 0.75000000000000000 faq(2)

Entity Cross-Validation Results (5 folds)

entity support f1-score precision recall
micro avg 926 0.77819751753912580 0.7777777777777778 0.7786177105831533
macro avg 926 0.58457934131482430 0.6098632206364536 0.5691473562625264
weighted avg 926 0.77196895125350020 0.7692782327167380 0.7786177105831533
city 384 0.86445012787723790 0.8492462311557789 0.8802083333333334
city.to 182 0.74168797953964180 0.6937799043062200 0.7967032967032966
city.from 149 0.66197183098591540 0.6962962962962963 0.6308724832214765
travel_flight_class 95 0.92146596858638740 0.9166666666666666 0.9263157894736842
iata 76 0.60000000000000000 0.6562500000000000 0.5526315789473685
iata.to 19 0.64705882352941170 0.7333333333333333 0.5789473684210527
iata.from 16 0.24000000000000005 0.3333333333333333 0.1875000000000000
number 5 N/A N/A N/A
github-actions[bot] commented 2 years ago

Intent Cross-Validation Results (5 folds)

class support f1-score confused_with
macro avg 2517 0.71269590430573320 N/A
weighted avg 2517 0.79770671022896370 N/A
faq 643 0.78756476683937810 inquire-ask_clarification-offsets(18), inform(15)
inform 616 0.93887530562347190 faq(25), deny_flying(3)
affirm 255 0.87025948103792420 faq(7), inform(7)
inquire-ask_clarification-offsets 124 0.70445344129554650 faq(26), buy_offsets(3)
estimate_emissions 73 0.57553956834532370 faq(14), affirm(4)
deny 69 0.76562500000000010 affirm(4), faq(4)
greet 63 0.87603305785123970 faq(7), SCENARIO(2)
insult 63 0.67796610169491520 vulgar(8), faq(5)
why 59 0.72413793103448280 faq(10), inquire-ask_clarification-offsets(2)
inform_notunderstanding 58 0.51923076923076930 faq(16), affirm(3)
farewell 57 0.78095238095238110 faq(6), affirm(2)
thank 54 0.89285714285714290 faq(2), insult(1)
express_positive-emo 48 0.67368421052631580 faq(6), affirm(3)
vulgar 46 0.62921348314606750 insult(9), faq(7)
express_uncertainty 43 0.64516129032258060 faq(5), inquire-ask_clarification(2)
express_surprise 43 0.69662921348314610 faq(8), inquire-ask_clarification(2)
inquire-ask_clarification 38 0.44444444444444440 faq(10), inquire-ask_clarification-offsets(6)
buy_offsets 35 0.65789473684210520 faq(7), affirm(1)
how_calculated 29 0.83018867924528300 faq(3), estimate_emissions(2)
deny_flying 28 0.68750000000000010 inform(2), faq(1)
express_negative-emo 25 0.65000000000000000 express_positive-emo(3), express_surprise(3)
restart 18 0.94736842105263160 N/A
meta_inform_problem_bad-link 12 0.96000000000000010 N/A
SCENARIO 10 0.70000000000000000 faq(1), greet(1)
help 8 0.18181818181818182 faq(4), inquire-ask_clarification(2), greet(1)

Entity Cross-Validation Results (5 folds)

entity support f1-score precision recall
micro avg 926 0.79092920353982310 0.8106575963718821 0.7721382289416847
macro avg 926 0.67524573003231690 0.7981977880531026 0.6162502790961981
weighted avg 926 0.78652673207650480 0.8087071365189759 0.7721382289416847
city 384 0.84848484848484850 0.8586666666666667 0.8385416666666666
city.to 182 0.75749318801089920 0.7513513513513513 0.7637362637362637
city.from 149 0.70945945945945940 0.7142857142857143 0.7046979865771812
travel_flight_class 95 0.92708333333333330 0.9175257731958762 0.9368421052631579
iata 76 0.68656716417910460 0.7931034482758621 0.6052631578947368
iata.to 19 0.46666666666666670 0.6363636363636364 0.3684210526315789
iata.from 16 0.43478260869565216 0.7142857142857143 0.3125000000000000
number 5 0.57142857142857150 1.0000000000000000 0.4000000000000000