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

[Feature] Add Cleanlab's Trustworthiness Score #572

Merged
merged 30 commits into from
Aug 29, 2024

Conversation

AshishSardana
Copy link
Contributor

Cleanlab provides trustworthiness score that can be used for guardrailing tasks. Read more about how this score is calculated here.

This PR aims to add support for a 3rd party API i.e. Cleanlab Studio's API, to enable users to use trustworthiness score for using guardrails on output.

Signed-off-by: Ashish Sardana <ashishsardana21@gmail.com>
Signed-off-by: Ashish Sardana <ashishsardana21@gmail.com>
Signed-off-by: Ashish Sardana <ashishsardana21@gmail.com>
@AshishSardana
Copy link
Contributor Author

Hi @drazvan, I'd like to add brief documentation about trustworthiness score and configurable parameter in the rail (threshold on least_trustworthiness_score).
Would it go here?

Also, how do I add tests? Do you store the keys on the CI server to be able to run the tests?

@drazvan
Copy link
Collaborator

drazvan commented Jul 1, 2024

@AshishSardana : Yes, you can add it in the library documentation. We are in the process of refactoring the structure a bit, but we'll change this as well once that's finalized.

Signed-off-by: Ashish Sardana <ashishsardana21@gmail.com>
Signed-off-by: Ashish Sardana <ashishsardana21@gmail.com>
Signed-off-by: Ashish Sardana <ashishsardana21@gmail.com>
@AshishSardana AshishSardana marked this pull request as ready for review July 2, 2024 23:07
Copy link
Contributor

@nelsonauner nelsonauner left a comment

Choose a reason for hiding this comment

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

Please take this review with a grain of salt. My comments are mainly to make our documentation more clear and succinct. I also try to facilitate usage of Cleanlab by using phrases like "It's easy to get started by doing X, Y and Z" instead of "It is required to do X if you want to use cleanlab"

I have some comments that are really more a preference, which I've prefaced with "Nit"

nemoguardrails/library/cleanlab/README.md Outdated Show resolved Hide resolved
nemoguardrails/library/cleanlab/README.md Outdated Show resolved Hide resolved
nemoguardrails/library/cleanlab/actions.py Outdated Show resolved Hide resolved
AshishSardana and others added 19 commits July 9, 2024 08:59
Co-authored-by: Nelson Auner <nelson@auner.org>
Signed-off-by: Ashish Sardana <ashishsardana21@gmail.com>
Signed-off-by: Ashish Sardana <ashishsardana21@gmail.com>
Signed-off-by: Ashish Sardana <ashishsardana21@gmail.com>
Signed-off-by: Ashish Sardana <ashishsardana21@gmail.com>
Signed-off-by: Ashish Sardana <ashishsardana21@gmail.com>
Signed-off-by: Ashish Sardana <ashishsardana21@gmail.com>
Signed-off-by: Ashish Sardana <ashishsardana21@gmail.com>
Signed-off-by: Ashish Sardana <ashishsardana21@gmail.com>
Signed-off-by: Ashish Sardana <ashishsardana21@gmail.com>
Signed-off-by: Ashish Sardana <ashishsardana21@gmail.com>
Co-authored-by: Nelson Auner <nelson@auner.org>
Signed-off-by: Ashish Sardana <ashishsardana21@gmail.com>
Signed-off-by: Ashish Sardana <ashishsardana21@gmail.com>
Signed-off-by: Ashish Sardana <ashishsardana21@gmail.com>
Signed-off-by: Ashish Sardana <ashishsardana21@gmail.com>
Signed-off-by: Ashish Sardana <ashishsardana21@gmail.com>
@AshishSardana
Copy link
Contributor Author

I'm not sure how the commit history got duplicated with my last a7517e3 commit.

No new changes are introduced in these duplicate commits.

Co-authored-by: Jonas Mueller <1390638+jwmueller@users.noreply.github.com>
Signed-off-by: Ashish Sardana <ashishsardana21@gmail.com>
@AshishSardana
Copy link
Contributor Author

Hi @drazvan, the PR is ready for review. Could you please give it a look?

Signed-off-by: Ashish Sardana <ashishsardana21@gmail.com>
Signed-off-by: Ashish Sardana <ashishsardana21@gmail.com>
@AshishSardana
Copy link
Contributor Author

Hi @Pouyanpi , I've resolved the conflicts.

@AshishSardana
Copy link
Contributor Author

Hi @Pouyanpi, please feel free to ask any clarifying questions!

@drazvan drazvan self-assigned this Aug 22, 2024
@drazvan drazvan self-requested a review August 22, 2024 16:52
@drazvan
Copy link
Collaborator

drazvan commented Aug 22, 2024

@AshishSardana, I'm just reviewing this, apologies for the delay. The code looks good, however, when I try to run it, I'm running into an error coming from the CleanLab python client.
Steps to reproduce:

  1. Edit the config.yml file for the examples/bots/abc bot:
rails:
#  input:
#    flows:
#      - self check input

  output:
    flows:
      - cleanlab trustworthiness

(comment the self-check input and replace the self-check output with cleanlab trustworthiness).

  1. Start the chat CLI nemoguardrails chat --config=examples/bots/abc --verbose.

  2. Say "hi"

Relevant error:

Traceback (most recent call last):
  File ".../nemoguardrails/nemoguardrails/actions/action_dispatcher.py", line 197, in execute_action
    result = await result
  File ".../nemoguardrails/nemoguardrails/library/cleanlab/actions.py", line 48, in call_cleanlab_api
    trustworthiness_score = await cleanlab_tlm.get_trustworthiness_score_async(
  File ".../nemoguardrails/venv/lib/python3.10/site-packages/cleanlab_studio/studio/trustworthy_language_model.py", line 559, in get_trustworthiness_score_async
    assert isinstance(prompt, Sequence) and isinstance(processed_response, Sequence)
AssertionError

From what I can see, the processed_response is actually a dict like {"response": "..."}.

Let me know if you're able to reproduce

@AshishSardana
Copy link
Contributor Author

@drazvan I was able to reproduce this error. We've pushed a fix to the cleanlab-studio package that you can fetch by pip install -U cleanlab-studio which resolves this error. Could you try?

Copy link
Collaborator

@drazvan drazvan left a comment

Choose a reason for hiding this comment

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

I was able to test and looks good 👍. Latency was a bit high in my tests, ~5s, but I guess that will be improved.

@drazvan drazvan merged commit 9fc92cd into NVIDIA:develop Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants