snipsco / snips-nlu

Snips Python library to extract meaning from text
https://snips-nlu.readthedocs.io
Apache License 2.0
3.89k stars 513 forks source link

custom brown clusters #827

Closed cahuja1992 closed 5 years ago

cahuja1992 commented 5 years ago

Brown clusters are shipped as a part of resources. How can we use custom cluster

adrienball commented 5 years ago

Hi @cahuja1992, Using custom resources is possible but not well documented yet, it will be improved and documented in the coming months.

In the meantime, here is the process that you can follow to use your own resources in english:

At this point, your custom english resources are setup and you can reference your new word clusters in the nlu engine configuration (cf https://snips-nlu.readthedocs.io/en/latest/tutorial.html#the-snips-nlu-engine)

I hope this helps, Cheers

adrienball commented 5 years ago

Another way to use custom resources consists in manually loading resources, updating them, and then pass the customized resources to SnipsNLUEngine():

from snips_nlu import SnipsNLUEngine
from snips_nlu.resources import load_resources
from snips_nlu.default_configs.config_en import CONFIG

resources = load_resources("en")
custom_clusters_name = "my_custom_clusters"
resources["metadata"]["word_clusters"].append(custom_clusters_name)
resources["word_clusters"][custom_clusters_name] = {
    "hello": "word_cluster1",
    "world": "word_cluster2"
}

config = CONFIG
# ... Update the config to leverage the new word clusters
engine = SnipsNLUEngine(config=config, resources=resources)
cahuja1992 commented 5 years ago

Thanks, it works.