Can I add more data to snips-nlu on the fly? - python-3.x

I am using snips-nlu to create a "simple" chatbot for managing certain tasks. But I seem to lack the understanding of how (if possible) to add new intents on the go during runtime.
The issue I face is let's say I have the following in my yaml file:
type: intent
name: questionAboutFood
slots:
- name: foodType
entity: foodType
utterances:
- what color is a [foodType]
- where can I buy a [foodType]
---
type: entity
name: foodType
automatically_extensible: yes
values:
- banana
- apple
- orange
from this file I can fit it to my snips-nlu engine.
But How do I during runtime append more foodTypes?
CODE:
from snips_nlu import SnipsNLUEngine
from snips_nlu.default_configs import CONFIG_EN
import io
import json
seed = 42
engine = SnipsNLUEngine(config=CONFIG_EN, random_state=seed)
with io.open("dataset.json") as f:
dataset = json.load(f)
engine.fit(dataset)
parsing = self.engine.parse("what color is the apple?")

I can see two workarounds:
Re-train
One way to do that consists in dynamically re-training the engine with the dataset updated with the additional entity values. This may be a reasonable solution if your dataset is not too big, as the training will be quite fast.
Improve the dataset
The other solution consists in providing many more formulations of your intent in the yaml file, so that the resulting engine will be able to extract unseen entity values.
In your case, you only provided two formulations in which the entity is the last token. Besides, the entity values you provided are only unigrams. For these reasons, it is likely that the NLU engine will not be able to capture entities when they span several tokens and/or when they are located in the middle of the sentence.
Here is a slightly better dataset which will already generalize much better:
type: intent
name: questionAboutFood
slots:
- name: foodType
entity: foodType
utterances:
- what color is a [foodType]
- what is the color of an [foodType] in general
- how much does an [foodType] cost
- can you describe a [foodType] for me please
- in which country is [foodType] generally found
- where can I buy a [foodType]
- how big are [foodType] in average
---
type: entity
name: foodType
automatically_extensible: yes
values:
- banana
- apple
- orange
- red meat
- black eyed pea
- brussels sprouts

Related

Use One TradingView Strategy for Multiple Coins connected to Bot

I'm a newbie for TradingView and have been learning a lot. I'm developing a strategy with backtesting using pine-script language however what confusing me, is how to use the same strategy for multiple coins.
The strategy is mainly developed for Binance Futures trading not sure if possible to apply it to other Exchangers.
So I wanna setup alerting system for multiple coins to be connected to 3comma Bot or Finandy to execute a trade based on the setup parameter.
My questions are.
If I wanna use certain candle types like Hiken Ashi should that be included in the code or just select it in the chart and it will be read by the strategy automatically?
Should I include the coins in the script or I should select them one by one in the chart and then setup an alert per coin?
Should I create one alert per one coin per chart or I should have multiple charts per each coin to setup an alert?
Should the timeframe also be defined in the code or the chart can do the job?
Sorry for many questions, I'm trying to understand the process well.
For multiple coins, the easiest way is to attach your strategy to each and every coin on Tradingview you want to trade with. This way you can backtest each on their respective chart.
If you create a strategy for say BINANCE:BTCUSDT and think of using this strategy on different exchange, you can do it, but first I suggest test it on BINANCE:BTCPERP and see for yourself how the same strategy can show a wildly different result (even though BTCUSDT and BTCPERP should be moving the same).
For a complex solution you can create a single script that uses multiple securities, but you won't be able to backtest that with simple approach, you would have to write your own gain/loss calculator, and you are not there yet.
I was going down the same road, my suggestions are:
create an input for the coin you want to trade (that will go into an input variable)
abstract the alert message off of the strategy.entry() command, that is, construct the alert message in a way you can replace values with variables in it (like the above selected coin)
3Commas needs a Bot ID to start/stop a bot, abstract that off as well, and you will have a good boilerplate code you can reuse many times
as a good practice (stolen from Kubernetes) besides the human readable name, I give a 5 letter identifier to every one of my bots, for easy recognition
A few examples. The below will create a selector for a coin and the Bot ID that is used to trade that coin. The names like 'BIN:GMTPERP - osakr' are entirely my making, they act as a Key (for a key/value pair):
symbol_choser = input.string(title='Ticker symbol', defval='BTC-PERP - aktqw', options=[FTX_Multi, 'FTX:MOVE Single - pdikr', 'BIN:GMTPERP - osakr', 'BIN:GMTPERP - rkwif', 'BTC-PERP - aktqw', 'BTC-PERP - ikrtl', 'BTC-PERP - cbdwe', 'BTC-PERP', 'BAL-PERP', 'RUNE-PERP', 'Paper Multi - fjeur', 'Paper Single - ruafh'], group = 'Bot settings')
exchange_symbol = switch symbol_choser // if you use Single Pair bots on 3Commas, the Value should be an empty string
'BIN:GMTPERP - osakr' => 'USDT_GMTUSDT'
'BTC-PERP - cbdwe' => 'USD_BTC-PERP'
'Paper Multi - fjeur' => 'USDT_ADADOWN'
bot_id = switch symbol_choser
'BIN:GMTPERP - osakr' => '8941983'
'BTC-PERP - cbdwe' => '8669136'
'Paper Multi - fjeur' => '8246237'
And now you can combine the above parts into two Alerts, for starting/stopping the bot:
alertMessage_Enter = '{"message_type": "bot", "bot_id": ' + bot_id + ', "email_token": "12345678-4321-abcd-xyzq-132435465768", "delay_seconds": 0, "pair": "' + exchange_symbol + '"}'
alertMessage_Exit = '{"action": "close_at_market_price", "message_type": "bot", "bot_id": ' + bot_id + ', "email_token": "12345678-4321-abcd-xyzq-132435465768", "delay_seconds": 0, "pair": "' + exchange_symbol + '"}'
exchange_symbol is the proper exchange symbol you need to provide to your bot, you can get help on the 3Commas' bot page (they have pre-crafted the HTTP requests you need to use for certain actions).
bot_id is the ID of your Bot, that is straightforward.
The above solution does not handle Single coin bots, their trigger message has a different structure.
Whenever you can, use Multi coin bots as they can act as a Single bot with two exception:
if you have a long spanning strategy and when you start a bot, you should be already in a trade, you can manually start a Single bot, but you cannot start a Multi coin bot (as there is no way to provide the coin info on which to start the trade)
if you are trading a derivative like FTX's MOVE contracts and your script is attached to the underlying BTC Futures. MOVE contracts changes name every day (the date is in their name, like: BTC-MOVE-0523) so you would need delete an alert, update and reapply the alert every day, etc. Instead, if your script is on the BTC-PERP then you can use a Single coin bot which does not expect a coin name in the alert message so it will start/stop the Bot on whatever coin it is connected to, then you need to change the coin name every day only in the Bot settings and never touch the Alert.
To summarize on your questions:
Do not include chart type in code (that is not even an embeddable data), just apply your code to whatever chart you want to use. Hint: never use Heikin-Ashi for trading. You can, but you will pay for it dearly (everyone tries, even against warnings, no worries)
Set up them one-by-one, so you can backtest them
No, set the timeframe on the chart. Later, when you will be more experienced you will be able to abstract the current timeframe (whatever it is) away and write code that is timeframe-agnostic. But that's hard and make your code less readable.

Why does Alloy-as-Markdown search for ModuleNameg.md rather than ModuleName.md given open ModuleName?

I have a .md file containing this fragment:
---
title: behaviour of vehicle locking system
layout: default
description: concrete example drawn from 2019 Ford Transit users handbook
---
```alloy
module VehicleLocking
open Vehicle
//etc
and the analyzer searches for Vehicleg.md rather than Vehicle.md. Why?

Deserializing custom types

The below xaml loosely describes a number of steps that can be re-arranged into many different configurations, and nested levels.
---
sequence:
- manual:
desc: unpack baloons
- electric:
desc: inflate each balloon
- parallel:
- manual:
desc: seal a balloon
- manual:
desc: sign a balloon
- sequence:
- manual:
desc: step 1
- manual:
desc: step 2
There are a number of *resolvers and *converters, however a good advice on which one to use when would be very helpful. How to register custom type factories and in what places?

Pulling product description information with API?

Is there a way to pull the product description area of a listing directly with the API? I'm able to get the title and bulletpoint information fine within the product API. But the product description area seems to be missing.
<Product>
<Identifiers>
<MarketplaceASIN>
<MarketplaceId>Removed</MarketplaceId>
<ASIN>B00BAWXD88</ASIN>
</MarketplaceASIN>
</Identifiers>
<AttributeSets>
<ns2:ItemAttributes xml:lang="en-US">
<ns2:Binding>Video Game</ns2:Binding>
<ns2:Brand>Xseed</ns2:Brand>
<ns2:Creator Role="Production Company">Xseed Jks Inc</ns2:Creator>
<ns2:Edition>Standard</ns2:Edition>
<ns2:ESRBAgeRating>Everyone 10+</ns2:ESRBAgeRating>
<ns2:Feature>The popular spinoff from the 'Harvest Moon' series returns, combining farming and family life with monster battling and taming, with an all-new story that's accessible to new players and series veterans alike</ns2:Feature>
<ns2:Feature>Whether it be governing as the prince, tilling the fields, interacting with townsfolk, or heading to a dungeon to take on dangerous foes, the diverse amount of activities ensure that each day is a new adventure</ns2:Feature>
<ns2:Feature>Use swords, spears, staffs and other weapons and magic to personalize your battle tactics as formidable monsters await in trap-laden dungeons; invite the townsfolk along, develop friendships with certain monsters and grow stronger together</ns2:Feature>
<ns2:Feature>The main character can be male or female, and either gender can woo marriage candidates from among the townsfolk; communication and gift giving will be key to romance, potentially resulting in marriage and perhaps an adorable child together</ns2:Feature>
<ns2:Feature>The popular spinoff from the 'Harvest Moon' series returns, combining farming and family life with monster battling and taming, with an all-new story that's accessible to new players and series veterans alike</ns2:Feature>
<ns2:Feature>Whether it be governing as the prince, tilling the fields, interacting with townsfolk, or heading to a dungeon to take on dangerous foes, the diverse amount of activities ensure that each day is a new adventure</ns2:Feature>
<ns2:Feature>Use swords, spears, staffs and other weapons and magic to personalize your battle tactics as formidable monsters await in trap-laden dungeons; invite the townsfolk along, develop friendships with certain monsters and grow stronger together</ns2:Feature>
<ns2:Feature>The main character can be male or female, and either gender can woo marriage candidates from among the townsfolk; communication and gift giving will be key to romance, potentially resulting in marriage and perhaps an adorable child together</ns2:Feature>
<ns2:Genre>role-playing-game-genre</ns2:Genre>
<ns2:HardwarePlatform>nintendo_3ds</ns2:HardwarePlatform>
<ns2:ItemDimensions>
<ns2:Height Units="inches">5.40</ns2:Height>
<ns2:Length Units="inches">0.40</ns2:Length>
<ns2:Width Units="inches">4.90</ns2:Width>
<ns2:Weight Units="pounds">0.10</ns2:Weight>
</ns2:ItemDimensions>
<ns2:IsAdultProduct>false</ns2:IsAdultProduct>
<ns2:IsEligibleForTradeIn>true</ns2:IsEligibleForTradeIn>
<ns2:Label>Xseed</ns2:Label>
<ns2:Languages>
<ns2:Language>
<ns2:Name>english</ns2:Name>
<ns2:Type>Published</ns2:Type>
</ns2:Language>
<ns2:Language>
<ns2:Name>english</ns2:Name>
<ns2:Type>Original Language</ns2:Type>
</ns2:Language>
<ns2:Language>
<ns2:Name>english</ns2:Name>
<ns2:Type>Unknown</ns2:Type>
</ns2:Language>
</ns2:Languages>
<ns2:ListPrice>
<ns2:Amount>29.99</ns2:Amount>
<ns2:CurrencyCode>USD</ns2:CurrencyCode>
</ns2:ListPrice>
<ns2:Manufacturer>Xseed</ns2:Manufacturer>
<ns2:ManufacturerMinimumAge Units="months">12.00</ns2:ManufacturerMinimumAge>
<ns2:Model>81356</ns2:Model>
<ns2:NumberOfItems>1</ns2:NumberOfItems>
<ns2:OperatingSystem>nintendo_3ds</ns2:OperatingSystem>
<ns2:PackageDimensions>
<ns2:Height Units="inches">0.70</ns2:Height>
<ns2:Length Units="inches">5.40</ns2:Length>
<ns2:Width Units="inches">4.90</ns2:Width>
<ns2:Weight Units="pounds">0.15</ns2:Weight>
</ns2:PackageDimensions>
<ns2:PackageQuantity>1</ns2:PackageQuantity>
<ns2:PartNumber>81356</ns2:PartNumber>
<ns2:PegiRating>ages_7_and_over</ns2:PegiRating>
<ns2:Platform>Nintendo 3DS</ns2:Platform>
<ns2:ProductGroup>Video Games</ns2:ProductGroup>
<ns2:ProductTypeName>CONSOLE_VIDEO_GAMES</ns2:ProductTypeName>
<ns2:PublicationDate>2013-10-02</ns2:PublicationDate>
<ns2:Publisher>Xseed</ns2:Publisher>
<ns2:ReleaseDate>2013-10-01</ns2:ReleaseDate>
<ns2:SmallImage>
<ns2:URL>http://ecx.images-amazon.com/images/I/617jaCu3H5L._SL75_.jpg</ns2:URL>
<ns2:Height Units="pixels">65</ns2:Height>
<ns2:Width Units="pixels">75</ns2:Width>
</ns2:SmallImage>
<ns2:Studio>Xseed</ns2:Studio>
<ns2:Title>Rune Factory 4 - Nintendo 3DS</ns2:Title>
</ns2:ItemAttributes>
</AttributeSets>
<Relationships/>
<SalesRankings>
<SalesRank>
<ProductCategoryId>video_games_display_on_website</ProductCategoryId>
<Rank>467</Rank>
</SalesRank>
<SalesRank>
<ProductCategoryId>4924892011</ProductCategoryId>
<Rank>22</Rank>
</SalesRank>
</SalesRankings>
</Product>
Amazon is providing _GET_MERCHANT_LISTINGS_DATA_, based on that we can get active product listing from amazon.
Report provide information like sku,title,description,ASIN..etc.. and It will give you information marketplace wise
You can get more info about report from below link.
http://docs.developer.amazonservices.com/en_US/reports/Reports_ReportType.html
This may help you.

multiple many to many relationships with bookshelf.js

I'm trying to determine the best way to represent the following using Bookshelf.js:
I have an Appointment model and each Appointment has:
1 or more Pet(s)
1 or more Service(s)
I'm able to easily represent this using many to many relationships in Bookshelf, which results in three tables: appointment, appointment_pet, and appointment_service.
I now have a new requirement that requires the ability to specify the Service(s) that are associated with each Pet on a per-appointment basis so that the services associated with a particular pet may be easily retrieved. For example:
Appointment 1
Has 1 Pet
Has 2 Services (walk, water plants)
Pet is associated with walk service only.
Getting all services for the Pet associated with Appointment 1 would return walk.
Is there an optimal way to represent this scenario using Bookshelf?
I'm considering that any Pet is always associated with a Service. In that case, I would structure it like:
As in, the Service model works as the bridge between an Appointment and the Pets. The Service can have a pet (e.g. when it's walk) or not (e.g. when it's water plants). The BookshelfJS model would look like:
var Appointment = bookshelf.Model.extend({
services: function () {
return this.hasMany('Service');
},
pets: function () {
return this.hasMany('Pet').through('Service');
},
});
A possible issue is that you'll end up with many different Services of the same type, but for different combinations of Appointment and Pet. This isn't problematic, if there're not many attributes on Service. For example, if Service has only a type attribute.
If you want to add more attributes to Service, say a price, time_duration, etc., you could extract it in its own table, as:
Then the Service table will have each type of service with its attributes (e.g. price, time_duration, ...). The code would look like:
var Appointment = bookshelf.Model.extend({
services: function () {
return this.hasMany('Service').through('AppointmentService');
},
pets: function () {
return this.hasMany('Pet').through('AppointmentService');
},
});
I would suggest going with the simpler case, and changing that if needed afterwards. You also might need to use the withPivot method to get the values from the relationship tables.

Resources