Skip to content

Commit

Permalink
Added Github Actions example
Browse files Browse the repository at this point in the history
  • Loading branch information
in4margaret committed Feb 11, 2020
1 parent 44fe5bb commit 220d6ca
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Detailed information on the CLI tool sub-commands and arguments can be found in
- [Dialogflow endpoint configuration](docs/DialogflowEndpointConfiguration.md)
- [Configuring LUIS CI/CD with Azure Pipelines](docs/AzurePipelines.md)
- [Extending the CLI to new NLU providers](docs/CliExtensions.md)
- [GitHub Actions workflow using NLU.DevOps cli tool](docs/NLUGitHubActions.md)

## Contributing

Expand Down
85 changes: 85 additions & 0 deletions docs/NLUGitHubActions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
## GitHub Actions workflow using NLU.DevOps cli tool

This documents walk through building a CI pipeline for LUIS using GitHub Actions and NLU.DevOps.
The workflow will be the following: 
1. create, train, publish the LUIS model using sample utterances
2. send a test set to created LUIS model
3. evaluate model by comparing results received from LUIS with expected values
4. delete the model from the portal

Let's name this pipeline CINLU and run it on a pull request to GitHub repo.

```
name: CINLU
on: [pull_request]
```

1. Let's install NLU.DevOps cli tool on GitHub agent.

```
- name: Install dotnet-nlu
run: dotnet tool install -g dotnet-nlu
```
On the ubuntu agent, you need to prepend a directory to the system PATH variable for all subsequent actions in the current job to make sure that cli tool works. More about this command [here](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/development-tools-for-github-actions#add-a-system-path-add-path).

```
- name: Path
run: echo "::add-path::$HOME/.dotnet/tools"
```
We use [utterances.json](../models/utterances.json) for training. You can replace this file with another file that consists of intents, utterances, entities that you need for your own model.
More about the format of this file [here](https://github.com/microsoft/NLU.DevOps/blob/master/docs/GenericUtterances.md).
To train your model we should add the following:

```
- name: Train Luis model
run: dotnet nlu train -s luis -u utterances.json --save-appsettings
env:
luisAuthoringRegion: ${{ secrets.luisAuthoringRegion }}
luisAuthoringKey: ${{ secrets.luisAuthoringKey }}
```

More about the command [here](https://github.com/microsoft/NLU.DevOps/blob/master/docs/Train.md)
Before you push to the repo, you need to add credentials (at least luisAutoringKey and luisAuthoringRegion are required) to your GitHub Secrets. For example,
![credentials](./images/credentials.png)

You can open the Azure portal and copy LUIS Authoring Cognitive Service region and key. More about LUIS authoring resources [here](https://docs.microsoft.com/en-us/azure/cognitive-services/luis/luis-how-to-azure-subscription).
![luisAuthAzure](./images/luisAuthAzure.png)

You can find this information on LUIS.ai portal as well.
![luisCredentials](./images/luiscred.png)

where `Region` -> `luisAuthoringRegion` and `Primary key` -> `luisAuthoringKey`

2. To test LUIS model let's use [utterancesTest.json](../models/utterancesTest.json) file.
We can save the result in results.json file using `--save-appsettings` for training. We don't need then to provide additional information to the `test` command. 
Yaml may look like that:
```
- name: Test Luis model
run: dotnet nlu test -s luis -u utterancesTest.json -o results.json
env:
luisAuthoringRegion: ${{ secrets.luisAuthoringRegion }}
luisAuthoringKey: ${{ secrets.luisAuthoringKey }}
```
3. To evaluate results we use two files: `utterancesTest.json` that consists of utterances that are labeled with actual intents and entities and `results.json` file with intent and entity names/types that we get from created LUIS model.

```
- name: Compare Luis model
run: dotnet nlu compare -e utterancesTest.json -a results.json
```

If you open your GitHub build run for this command in the console, you can see something similar to
![compareResults](./images/compareResults.png)

You can see that we run 12 tests, 11 passed and 1 failed.

4. When you work on several hypotheses, sometimes you need only to get results and you don't want to keep the model. It is possible to delete the model in the same pipeline after you get results.
```
- name: Delete Luis model
run: dotnet nlu clean -s luis
env:
luisAuthoringRegion: ${{ secrets.luisAuthoringRegion }}
luisAuthoringKey: ${{ secrets.luisAuthoringKey }}
```

You can find GitHub Action workflow yaml file [here](../pipelines/.github/workflows/nlugithub.yml).
Binary file added docs/images/compareResults.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/credentials.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/luisAuthAzure.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/luiscred.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions models/utterancesTest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[
{
"text": "start playing music",
"intent": "PlayMusic"
},
{
"text": "play music",
"intent": "PlayMusic"
},
{
"text": "listen to hip hop",
"intent": "PlayMusic"
},
{
"text": "is it cold out",
"intent": "None"
},
{
"text": "how many days until Christmas",
"intent": "None"
},
{
"text": "what's the weather like",
"intent": "None"
}
]

50 changes: 50 additions & 0 deletions pipelines/.github/workflows/nlugithub.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: CINLU

on: [pull_request]

jobs:
build:
name: Build Code
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1

- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 2.2.108

- name: Install dotnet-nlu
run: dotnet tool install -g dotnet-nlu

- name: Path
run: echo "::add-path::$HOME/.dotnet/tools"

- name: Train Luis model
run: dotnet nlu train -s luis -u utterances.json --save-appsettings
env:
luisAuthoringRegion: ${{ secrets.luisAuthoringRegion }}
luisAuthoringKey: ${{ secrets.luisAuthoringKey }}

- name: Test Luis model
run: dotnet nlu test -s luis -u utterancesTest.json -o results.json
env:
luisAuthoringRegion: ${{ secrets.luisAuthoringRegion }}
luisAuthoringKey: ${{ secrets.luisAuthoringKey }}

- name: Compare Luis model
run: dotnet nlu compare -e utterancesTest.json -a results.json

- name: Archive TestResult
uses: actions/upload-artifact@v1
with:
name: TestResult
path: TestResult.xml

- name: Delete Luis model
run: dotnet nlu clean -s luis
env:
luisAuthoringRegion: ${{ secrets.luisAuthoringRegion }}
luisAuthoringKey: ${{ secrets.luisAuthoringKey }}

0 comments on commit 220d6ca

Please sign in to comment.