Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EN] Add more english sentences for lock get state queries #2219

Merged
merged 10 commits into from
Jul 7, 2024

Conversation

ViViDboarder
Copy link
Contributor

@ViViDboarder ViViDboarder commented Jun 6, 2024

Add some new permutations of lock sentence queries.

Summary by CodeRabbit

  • New Features

    • Enhanced the HassGetState intent to support more flexible and varied sentence structures for querying the state of locks, doors, and windows in specific areas.
  • Improvements

    • Refined language for querying lock states to improve user interaction and clarity.

Copy link

coderabbitai bot commented Jun 6, 2024

Walkthrough

The recent updates to the HassGetState intent in the lock domain focus on enhancing user interaction by introducing varied sentence structures for querying the status of locks, doors, and windows. These changes provide more flexibility and natural language options for users. Additionally, test queries have been refined to better align with the updated intent patterns, ensuring more precise and user-friendly responses.

Changes

Files Change Summary
sentences/en/lock_HassGetState.yaml Updated sentence patterns in HassGetState intent to include variations for querying lock states.
tests/en/lock_HassGetState.yaml Refined test queries to reflect the updated intent patterns and added a new test for specific door status.

Sequence Diagram(s) (Beta)

sequenceDiagram
    participant User
    participant System

    User->>System: "Is the Front Door locked?"
    System-->>User: "Yes, the Front Door is locked."

    User->>System: "Do I have any unlocked doors?"
    System-->>User: "No, all doors are locked."

    User->>System: "Which doors are currently locked?"
    System-->>User: "The Front Door and the Back Door are locked."
Loading

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@tetele tetele left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All in all good changes, but there are one or two things which could be improved. Thanks!

sentences/en/lock_HassGetState.yaml Outdated Show resolved Hide resolved
sentences/en/lock_HassGetState.yaml Outdated Show resolved Hide resolved
sentences/en/lock_HassGetState.yaml Outdated Show resolved Hide resolved
@home-assistant home-assistant bot marked this pull request as draft June 7, 2024 09:48
@home-assistant
Copy link

home-assistant bot commented Jun 7, 2024

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@ViViDboarder ViViDboarder marked this pull request as ready for review June 7, 2024 16:45
@home-assistant home-assistant bot requested a review from tetele June 7, 2024 16:45
Copy link
Contributor

@tetele tetele left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't addressed each individual line, but you have 3 types of issues:

  1. Removing all optional parts in a set of sentences basically produces the same sentence template. This makes for very inefficient (slow) matching.
  2. Whitespace should be part of the optional part, i.e. unlock [the ]{name} instead of unlock [the] {name}. This also prevents inefficiency, as internally, the 2 spaces before and after [the] would have to match a single space in the transcribed sentence, which is slower than it having to match a single whitespace.
  3. The securely adverb should probably be an optional part of the input string of the lock_states list, rather than included in each sentence. You can't call something securely unlocked.

sentences/en/lock_HassGetState.yaml Outdated Show resolved Hide resolved
sentences/en/lock_HassTurnOff.yaml Outdated Show resolved Hide resolved
sentences/en/lock_HassTurnOff.yaml Outdated Show resolved Hide resolved
@home-assistant home-assistant bot marked this pull request as draft June 14, 2024 17:06
@ViViDboarder ViViDboarder marked this pull request as ready for review June 14, 2024 19:16
@home-assistant home-assistant bot requested a review from tetele June 14, 2024 19:16
Copy link
Contributor

@tetele tetele left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please review my comment here #2219 (review)

@@ -3,34 +3,42 @@ intents:
HassGetState:
data:
- sentences:
- "is <name> {lock_states:state} [in <area>]"
- "(is|are) <name> ([<currently>];{lock_states:state} [in <area>])"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't have a completely optional permutation item, as skipping <currently> would match both the optional part at the beginning and at the end, which is inefficient. Also, watch out for spaces before/after optional parts.

Suggested change
- "(is|are) <name> ([<currently>];{lock_states:state} [in <area>])"
- "(is|are) <name> (<currently>;{lock_states:state}[ in <area>])"
- "(is|are) <name> {lock_states:state}[ in <area>]"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not seeing any significant difference in performance when I run benchmarks over 324,000 sentences.

The performance seems to flip flop a bit between the two versions and, even taking worst case difference (0.5s for a benchmark iteration), that comes out to be 0.5, which is one micro second.

With that in consideration, it feels like optimizing for ease of maintenance is more important to giving users a good experience. My worry is not so much making this one change, but doing this for every intent type and then expanding for other common utterances.

Methodology:

# Number of generated sentences
$ python3 -m hassil.sample ./split_permutations.yaml --areas kitchen --names "front door" | jq -r .text | sort | uniq | wc -l
# Benchmarking with split sentences (your diff)
$ set PERMUTATIONS (python3 -m hassil.sample ./split_permutations.yaml --areas kitchen --names "front door" | jq -r .text)                                                                                                                             [.venv]
  time for i in (seq 1000)
      echo $PERMUTATIONS | hassil ./split_permutations.yaml --areas kitchen --names "front door" 2&> /dev/null
  end

________________________________________________________
Executed in   83.68 secs    fish           external
   usr time   56.92 secs  353.69 millis   56.56 secs
   sys time   14.81 secs  391.86 millis   14.42 secs
# Benchmarking with optional permutations
$ set PERMUTATIONS (python3 -m hassil.sample ./empty_permutations.yaml --areas kitchen --names "front door" | jq -r .text)                                                                                                                             [.venv]
  time for i in (seq 1000)
      echo $PERMUTATIONS | hassil ./empty_permutations.yaml --areas kitchen --names "front door" 2&> /dev/null
  end

________________________________________________________
Executed in   82.60 secs    fish           external
   usr time   56.22 secs  377.65 millis   55.85 secs
   sys time   14.59 secs  398.24 millis   14.20 secs

empty_permutations.yaml

:hassil:Area names: ['kitchen']
language: en
intents:
  HassGetState:
    data:
      - sentences:
          - "(is|are) <name> ([<currently>];{lock_states:state} [in <area>])"
        response: one_yesno
expansion_rules:
  name: "[the] {name}"
  area: "[the] {area}"
  currently: "(currently|presently|right now|at the moment)"
lists:
  lock_states:
    values:
      - in: "[securely ]locked"
        out: "locked"
      - in: "unlocked"
        out: "unlocked"

split_permutations.yaml

language: en
intents:
  HassGetState:
    data:
      - sentences:
          - "(is|are) <name> (<currently>;{lock_states:state} [in <area>])"
          - "(is|are) <name> {lock_states:state} [in <area>]"
        response: one_yesno
expansion_rules:
  name: "[the] {name}"
  area: "[the] {area}"
  currently: "(currently|presently|right now|at the moment)"
lists:
  lock_states:
    values:
      - in: "[securely ]locked"
        out: "locked"
      - in: "unlocked"
        out: "unlocked"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, that's interesting, i must admit. Simply looking at the code structure/complexity says that the split variant should be faster, but i guess that the complexity of other permutation items might have a role here as well.

Either way, I agree that for such minute performance differences, ease of maintenance should be prioritized.

@synesthesiam please take a look at the performance results above and let's discuss if we should change our approach regarding optimization enforcement.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wanted to see if any more thought has been given to this? I'd like to do another PR generalizing adding some more common values, then start to refactor sentences and generate new structures via an LLM.

It's pretty cool that we can now use an LLM in Assist, but I'm hoping to get things to feel more natural and flexible by letting the LLM generate sentences to match and then performing any actual sentence to intent matching offline.

sentences/en/lock_HassGetState.yaml Outdated Show resolved Hide resolved
sentences/en/lock_HassGetState.yaml Outdated Show resolved Hide resolved
sentences/en/lock_HassGetState.yaml Outdated Show resolved Hide resolved
sentences/en/lock_HassGetState.yaml Outdated Show resolved Hide resolved
sentences/en/lock_HassGetState.yaml Outdated Show resolved Hide resolved
sentences/en/lock_HassTurnOff.yaml Outdated Show resolved Hide resolved
sentences/en/lock_HassTurnOn.yaml Outdated Show resolved Hide resolved
@home-assistant home-assistant bot marked this pull request as draft June 17, 2024 11:29
@ViViDboarder ViViDboarder marked this pull request as ready for review July 4, 2024 00:01
@home-assistant home-assistant bot requested a review from tetele July 4, 2024 00:01
@tetele tetele merged commit 897ce9a into home-assistant:main Jul 7, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants