Rasa NLU: How to use multiple categorical slots with same values? - nlp

I just started working with Rasa NLU and I have some problem understanding the usage of categorical slots with same values. I have 3 different types of risk, each a categorical slot with values: low, medium and high.
How can the bot differentiate between the three risks and understand which slot to be filled up, given the intent is same for each.
Or do I need to use different intents for each?
Right now what I see is (I removed unrelated logs):
How tired are you?
1: low (low)
2: medium (medium)
3: high (high)
medium
DEBUG:rasa_core.processor:Received user message 'medium' with intent '{'name': 'inform', 'confidence': 0.88372623999657118}' and entities '[{'start': 0, 'end': 6, 'value': 'medium', 'entity': 'fatigue', 'extractor': 'ner_crf'}]'
DEBUG:rasa_core.processor:Current slot values:
fatigue: medium
injury: None
stress: None
How stressed are you?
1: low (low)
2: medium (medium)
3: high (high)
low
DEBUG:rasa_core.processor:Received user message 'low' with intent '{'name': 'inform', 'confidence': 0.88762049990079372}' and entities '[{'start': 0, 'end': 3, 'value': 'low', 'entity': 'fatigue', 'extractor': 'ner_crf'}]'
DEBUG:rasa_core.processor:Current slot values:
fatigue: low
injury: None
stress: None
All the user replies have the intent inform.
An example story is:
* _greet[]
- utter_ask_fatigue
* _inform[fatigue=low]
- utter_ask_injury
* _inform[injury=medium]
- utter_ask_stress
* _inform[stress=low]
- utter_on_it
- action_reply

you can do it with one entity and four slots
the entity may be defined as type "info", with text values (i.e. low, medium, high).
The four slots: the first one is "info", which will auto filled by recognized entity "info" defined previously. The other three would be "fatigue", "stress" and "injury", which can be filled by bot actions such as action_fill_fatigue, action_fill_stress and action_fill_injury.
an example story will make it clear:
* _greet[]
- utter_ask_fatigue
* _inform[info=low]
- action_fill_fatigue
- utter_ask_injury
* _inform[info=medium]
- action_fill_injury
- utter_ask_stress
* _inform[info=low]
- action_fill_stress
- utter_on_it
- action_reply

Related

AWARE method in ecoinvent through brightway2

i'm trying to extract all water inputs to several processes using brightway or ab, but i'm having troubles getting those values from the inventory_matrix. I need to get quantity of water consumed and origin of the water (surface, well, unspecified, tap water) along with its geography. mI'm using ecoinvent 3.7.1
One way i thought i could do that is create an impact assessment method with CFs for those compartments (each of those will be 1s), then apply it to the processes and analyse the elementary flows contributions.
I'm not sure though i can get the geography like this.
EDITED MOST OF THE QUESTION FOR CLARITY
Seems like i was trying to reinvent the wheel! My goal is to implement AWARE method and apply it to quite a few processes. the best result would be to use AWARE through activity-browser so i can use all of its functionalities which are very time-saving for me.
i just saw that there is brightway2-regional and bw2_aware that implement the aforementioned method.
So i'm now trying to install the packages in my brightway2 conda environment.
Managed to get bw2regional through conda but i cant manage to install bw2_aware if not through pip.
managed to install bw2_aware by using the wheel file and pip install --no-deps and then tweaking a line in the source code for fiona import, now i'm getting errors when running
bwr.bw2regionalsetup()
bw2_aware.import_aware()
SSLError: HTTPSConnectionPool(host='pandarus.brightwaylca.org', port=443): Max retries exceeded with url: / (Caused by SSLError(CertificateError("hostname 'pandarus.brightwaylca.org' doesn't match either of '*.parkingcrew.net', 'parkingcrew.net'",),))
Now i'm trying to understand if i can apply this to ecoinvent, and how. i'm really unsure if i can add the different geographies to the elementary flows in the database, so that i can correctly calculte aware in a lca.
I already saw that importing AWARE allows to choose it as a impact cathegory in activity-browser, though i cannot see the geographies in the CFS shown in the Charaterization Factors tab.
So i then tried to calculate an LCA with AB using AWARE method and 2 sample processes:
diesel, burned in agricultural machinery | diesel, burned in agricultural machinery | GLO | megajoule | ECOINVENT3.7.1
electricity, high voltage | market for electricity, high voltage | IT | kilowatt hour | ECOINVENT3.7.1
and i get this result (first is Agricultural, the other is non Agricultural):
diesel, burned in agricultural machinery | GLO
0.014757994762941706 0.00654978730728395
market for electricity, high voltage | IT 0.285207979534988 0.12657895834095712
I wonder if this is correct.
Your intuition is correct - constructing an LCIA method is an easy way to do this. This is because there are unspoken assumptions behind these flows - they will be mostly positive numbers, but some represent consumption, while others represent release.
Here is an example using Brightway 2.5, it would need to be adapted for version 2:
import bw2data as bd
import bw2calc as bc
import numpy as np
bd.projects.set_current("ecoinvent 3.7.1")
ecoinvent = bd.Database("ecoinvent 3.7.1")
beet = ecoinvent.search("beet")[1]
water_method = bd.Method(("Water", "raw"))
water_method.register()
water_method.write([(x, -1 if x['categories'][0] == 'natural resource' else 1)
for x in bd.Database("biosphere3")
if x['name'].startswith('Water')])
demand, data_objs, _ = bd.prepare_lca_inputs(demand={beet: 1}, method=("Water", "raw"))
lca = bc.LCA(demand=demand, data_objs=data_objs)
lca.lci()
lca.lcia()
coo = lca.characterized_inventory.tocoo()
results = sorted(zip(np.abs(coo.data), coo.data, coo.row, coo.col), reverse=True)
for a, b, c, d in results[:10]:
print("{:.6f}\t{}\n\t\t{}".format(
float(b),
bd.get_activity(lca.dicts.biosphere.reversed[c]),
bd.get_activity(lca.dicts.activity.reversed[d])
))
With the result:
0.009945 'Water' (cubic meter, None, ('water',))
'electricity production, hydro, run-of-river' (kilowatt hour, CH, None)
-0.009945 'Water, turbine use, unspecified natural origin' (cubic meter, None, ('natural resource', 'in water'))
'electricity production, hydro, run-of-river' (kilowatt hour, CH, None)
0.009514 'Water' (cubic meter, None, ('water',))
'electricity production, hydro, run-of-river' (kilowatt hour, RoW, None)
-0.009514 'Water, turbine use, unspecified natural origin' (cubic meter, None, ('natural resource', 'in water'))
'electricity production, hydro, run-of-river' (kilowatt hour, RoW, None)
0.007264 'Water' (cubic meter, None, ('water',))
'electricity production, hydro, run-of-river' (kilowatt hour, FR, None)
-0.007264 'Water, turbine use, unspecified natural origin' (cubic meter, None, ('natural resource', 'in water'))
'electricity production, hydro, run-of-river' (kilowatt hour, FR, None)
-0.003371 'Water, river' (cubic meter, None, ('natural resource', 'in water'))
'irrigation, sprinkler' (cubic meter, CH, None)
0.003069 'Water' (cubic meter, None, ('water', 'ground-'))
'sugar beet production' (kilogram, CH, None)
0.001935 'Water' (cubic meter, None, ('air',))
'sugar beet production' (kilogram, CH, None)
0.001440 'Water' (cubic meter, None, ('water',))
'electricity production, hydro, run-of-river' (kilowatt hour, CN-SC, None)
There isn't a way to use regionalized calculations in the activity browser, and the AWARE method (incorrectly) relies on an external web service which is not strictly necessary. So the short answer is that this isn't possible right now, but as you are the second person to ask about this in a week, we need to get it working ASAP.

Renaming dictionary keys through a loop problem

I have a column, 'EDU', in my dataframe, df. where I tried to create a dictionary with value_counts(), poe_dict. It looks like this.
edu_m=df['EDU'].sort_values()
poe_dict = edu_m.value_counts(normalize=True).to_dict()
poe_dict
{4: 0.47974705779026877,
3: 0.24588090637625154,
2: 0.172352011241876,
1: 0.10202002459160373}
Now, I'm trying to replace the keys '4,3,2,1' with these strings which I put in a list.
n_keys=["college","more than high school but not college","high school","less than high school"]
If I do each of them individually, this runs ok, giving me the expected result.
In:
poe_dict['college'] = poe_dict.pop(4)
poe_dict['more than high school but not college'] = poe_dict.pop(3)
poe_dict['high school'] = poe_dict.pop(2)
poe_dict['less than high school'] = poe_dict.pop(1)
Out:
{'college': 0.47974705779026877,
'more than high school but not college': 0.24588090637625154,
'high school': 0.172352011241876,
'less than high school': 0.10202002459160373}
however, if I try to do it as a loop, it produces this.
In:
for key, n_key in zip(poe_dict.keys(), n_keys):
poe_dict[n_key] = poe_dict.pop(key)
poe_dict
Out:
{2: 0.172352011241876,
1: 0.10202002459160373,
'high school': 0.47974705779026877,
'less than high school': 0.24588090637625154}
So I dont understand why the loop does not work for keys 2 and 1?
I have tried to debug it as well to see what happens in the loop like this.
In:
for key, n_key in zip(poe_dict.keys(), n_keys):
print (key,n_key)
poe_dict[n_key] = poe_dict.pop(key)
Out:
4 college
3 more than high school but not college
college high school
more than high school but not college less than high school
You loop over the keys of poe_dict in the for loop. However the keys of poe_dict is modified when the statement is poe_dict[n_key] = poe_dict.pop(key) has been run. Therefore, the keys information gets wrong. The correct way is to store the keys of peo_dict into a list list(poe_dict.keys()) and loop over this new list of keys.
poe_dict = {4: 0.47, 3:0.25, 2:0.17, 1:0.10}
n_keys = ['college', 'more than high school but not college','high school', 'less than high school' ]
keylist = list(poe_dict.keys())
for key, n_key in zip(keylist, n_keys):
print (key,n_key)
poe_dict[n_key] = poe_dict.pop(key)
print (poe_dict)
The results will be
{'college': 0.47, 'more than high school but not college': 0.25, 'high school': 0.17, 'less than high school': 0.1}

What is "personastateflags"?

I requesting this endpoint https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=XXX&steamids=76561198049710886
And I'm getting this reply:
{
"response":{
"players":[
{
"steamid":"76561198049710886",
"communityvisibilitystate":3,
"profilestate":1,
"personaname":"testing",
"lastlogoff":1570961241,
"profileurl":"https://steamcommunity.com/id/danpool/",
"avatar":"https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/1b/1b5db030143e6110de8558adf4235ece591ddde1.jpg",
"avatarmedium":"https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/1b/1b5db030143e6110de8558adf4235ece591ddde1_medium.jpg",
"avatarfull":"https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/1b/1b5db030143e6110de8558adf4235ece591ddde1_full.jpg",
"personastate":0,
"realname":"John Doe",
"primaryclanid":"103582791429521408",
"timecreated":1317282093,
"personastateflags":0,
"loccountrycode":"NO"
}
]
}
}
But i'm confused what personastateflags means, I find some stuff by searching for it but they all different and official docs don't have any information about it.
last one i found is this one:
1: 'Offline', 2: 'Online', 4: 'Golden',
64: 'Online using Big Picture',
256: 'Online using Web Client',
512: 'Online using Mobile',
1024: 'Online using Steam Controller'
but personastateflags is 0 in most cases so it doesn't make any sense :/
I also tried to launching big picture mode while I was online, and result was "1024" which would be "Online using Steam Controller" and not correct.
P.S.
I successfully converted personastate using this object
0: 'Offline', 1: 'Online', 2: 'Busy',
3: 'Away', 4: 'Snooze', 5 :'Looking to Trade',
6: 'Looking to Play'
I have not read into steam docs, but it should mean that the user is offline.
Here is what docs say:
The user's current status. 0 - Offline, 1 - Online, 2 - Busy, 3 - Away, 4 - Snooze, 5 - looking to trade, 6 - looking to play. If the player's profile is private, this will always be "0", except is the user has set their status to looking to trade or looking to play, because a bug makes those status appear even if the profile is private.

Artillery.io: How to generate test report for each Scenario?

Artillery: How to run the scenarios sequentially and also display the results of each scenario in the same file?
I'm currently writing nodejs test with artillery.io to compare performance between two endpoints that I implemented. I defined two scenarios and I would like to get the result of each in a same report file.
The execution of the tests is not sequential, it means that at the end of the test I have a result already combined and impossible to know the performance of each one but for all.
config:
target: "http://localhost:8080/api/v1"
plugins:
expect: {}
metrics-by-endpoint: {}
phases:
- duration: 60
arrivalRate: 2
environments:
dev:
target: "https://backend.com/api/v1"
phases:
- duration: 60
arrivalRate: 2
scenarios:
- name: "Nashhorn"
flow:
- post:
url: "/casting/nashhorn"
auth:
user: user1
pass: user1
json:
body:
fromFile: "./casting-dataset-01-as-input.json"
options:
filename: "casting_dataset"
conentType: "application/json"
expect:
statusCode: 200
capture:
regexp: '[^]*'
as: 'result'
- log: 'result= {{result}}'
- name: "Nodejs"
flow:
- post:
url: "/casting/nodejs"
auth:
user: user1
pass: user1
json:
body:
fromFile: "./casting-dataset-01-as-input.json"
options:
filename: "casting_dataset"
conentType: "application/json"
expect:
statusCode: 200
capture:
regexp: '[^]*'
as: 'result'
- log: 'result= {{result}}'
How to run the scenarios sequentially and also display the results of each scenario in the same file?
Thank you in advance for your answers
I think you miss the param weight, this param defines de probability to execute the scenario. if in you first scenario put a weight of 1 and in the second put the same value, both will have the same probability to been execute (50%).
If you put in the first scenario a weight of 3 and in the second one a weight of 1, the second scenario will have a 25% probability of execution while the first one will have a 75% probability of being executed.
This combined with the arrivalRate parameter and setting the value of rampTo to 2, will cause 2 scenarios to be executed every second, in which if you set a weight of 1 to the two scenarios, they will be executed at the same time.
Look down for scenario weights in the documentation
scenarios:
- flow:
- log: Scenario for GET requests
- get:
url: /v1/url_test_1
name: Scenario for GET requests
weight: 1
- flow:
- log: Scenario for POST requets
- post:
json: {}
url: /v1/url_test_2
name: Scenario for POST
weight: 1
I hope this helps you.
To my knowledge, there isn't a good way to do this with the existing the artillery logic.
using this test script:
scenarios:
- name: "test 1"
flow:
- post:
url: "/postman-echo.com/get?test=123"
weight: 1
- name: "test 2"
flow:
- post:
url: "/postman-echo.com/get?test=123"
weight: 1
... etc...
Started phase 0 (equal weight), duration: 1s # 13:21:54(-0500) 2021-01-06
Report # 13:21:55(-0500) 2021-01-06
Elapsed time: 1 second
Scenarios launched: 20
Scenarios completed: 20
Requests completed: 20
Mean response/sec: 14.18
Response time (msec):
min: 117.2
max: 146.1
median: 128.6
p95: 144.5
p99: 146.1
Codes:
404: 20
All virtual users finished
Summary report # 13:21:55(-0500) 2021-01-06
Scenarios launched: 20
Scenarios completed: 20
Requests completed: 20
Mean response/sec: 14.18
Response time (msec):
min: 117.2
max: 146.1
median: 128.6
p95: 144.5
p99: 146.1
Scenario counts:
test 7: 4 (20%)
test 5: 2 (10%)
test 3: 1 (5%)
test 1: 4 (20%)
test 9: 2 (10%)
test 8: 3 (15%)
test 10: 2 (10%)
test 4: 1 (5%)
test 6: 1 (5%)
Codes:
404: 20
So basically you can see that they are weighted equally, but are not running equally. So I think there needs to be something added to the code itself for artillery. Happy to be wrong here.
You can use the per endpoint metrics plugin to give you the results per endpoint instead of aggregated.
https://artillery.io/docs/guides/plugins/plugin-metrics-by-endpoint.html
I see you already have this in your config, but it cannot be working if it is not giving you what you need. Did you install it as well as add to config?
npm install artillery-plugin-metrics-by-endpoint
In terms of running sequentially, I'm not sure why you would want to, but assuming you do, you just need to define each POST as part of the same Scenario instead of 2 different scenarios. That way the second step will only execute after the first step has responded. I believe the plugin is per endpoint, not per scenario so will still give you the report you want.

Are eco-indicator endpoints reported in points or millipoints

How do I check if impacts are reported in—for example using 'eco-indicator 99, (H,A)', 'ecosystem quality', 'total'—in milli-points or points.
Metadata is stored in methods, so you should be able to do the following:
In [1]: methods[('eco-indicator 99, (H,A)', 'total', 'total')]['unit']
Out[1]: 'points'
You can also see complete method metadata:
In [1]: methods[('eco-indicator 99, (H,A)', 'total', 'total')]
Out[1]:
{'abbreviation': 'eco-indicator-99-hatt.418ee316e1a7611c9135b9abe7b490e7',
'description': 'Implementation of the impact assessment method with the normalized and weighted damage factor. Weights (30% human health, 50% ecosystem quality, 20% resources) and normalization for Egalitarian perspective. Correction of factors for nickel and chromium emissions and nickel and zinc resource. Own assessment for new land use categories.',
'filename': 'LCIA implementation v3.1 2014_08_13.xlsx',
'num_cfs': 1285,
'unit': 'points'}

Resources