文件历史

提交图

694 次代码提交

作者 SHA1 备注 提交日期
Hui Wen 06ed233a25 Error handling for rare classes (#455)
* error handling for rare classes

* change subtract to symmetric difference

* remove extra np.unique

* add warning for all instances of getting consensus labels

* error checking edits

* Add typing

Co-authored-by: Elías Snorrason <eliassno@gmail.com>

* black formatting

* update typing - labels_multiannotator will always already be converted to pd.dataframe

* make pred_probs options in typing

* add =None

* docstring edits

Co-authored-by: Jonas Mueller <1390638+jwmueller@users.noreply.github.com>

* add basic docstring

* Changed to verbose

* Removed unessesary calculation out of get_labels_quality_m

* Update cleanlab/multiannotator.py

* comment for lost classes check so it can be grepped

* caution about setting verbose to false

* advise against verbose=false in docstring

Co-authored-by: Elías Snorrason <eliassno@gmail.com>
Co-authored-by: Jonas Mueller <1390638+jwmueller@users.noreply.github.com>
Co-authored-by: Ulyana <ulyana@cleanlab.ai>
2022-09-16 19:26:29 -07:00
Jonas Mueller 7256cd3546 More improvements to token classification code and documentation (#452)
* improved token docs/code

* format paragraphs in docstrings

* fix typo

Co-authored-by: Elías Snorrason <eliassno@gmail.com>
2022-09-16 14:04:45 +00:00
Jonas Mueller 2959210c95 more links in keras wrapper docstrings 2022-09-15 20:20:31 -07:00
Jonas Mueller 0657b14792 add links in keras wrapper docs 2022-09-15 19:20:37 -07:00
Elías Snorrason bc2dabb764 Change output of display_issues (#450) 2022-09-15 18:05:46 -07:00
Elías Snorrason 95b0742342 Make softmin_sentence_score a private function (#449)
This scoring function is only used internally. Might as well be private.
2022-09-15 23:19:15 +00:00
Curtis G. Northcutt 1b813d9666 fix bug in hard-coded test. generalize the test (#448)
* fix bug in hard-coded test. generalize the test

* 🐛 cast rounded num_issues to int

np.rint outputs an array of the same shape and type as its input. num_label_issues is expected to return an integer.

Co-authored-by: Elías Snorrason <eliassno@gmail.com>
2022-09-15 18:16:56 -04:00
Jonas Mueller 1b76f4ff1b Improve docstrings for keras wrapper (#447)
* improved docstrings for keras wrapper

* hide inheritance from keras wrapper docstrings

* black formatting
2022-09-15 15:36:35 -04:00
Curtis G. Northcutt 3ff8fab2d9 make num_label_issues = cj calibrated offdiag sum (#445)
The discrepancy occurs because cj calibrated maintains a guarantee that it will perfectly count every example in the dataset (assumes no out of distribution examples).

You can see this when by following this change of methods:

* see `calibrate_confident_joint`, specifically this line here: https://github.com/cleanlab/cleanlab/blob/master/cleanlab/count.py#L172
* round here https://github.com/cleanlab/cleanlab/blob/9240a8c56d020abec8566a0a56d22dcb99d32528/cleanlab/internal/util.py#L209
* the actual rounding occurs here https://github.com/cleanlab/cleanlab/blob/9240a8c56d020abec8566a0a56d22dcb99d32528/cleanlab/internal/util.py#L174

the fix to make `num_label_issues` the same is just to round instead of flooring.

see the two GREEN columns in the attached image

> [nit] consider `np.rint()` instead of `np.round()` for clarity

good call. updated
2022-09-15 11:44:27 -07:00
Jonas Mueller a4ad6460a2 Format return docstrings and add typing (#437)
* typing and return docstrings

* address typing complaints

* allow redefinition

* typing complains for pandas

* .values -> to_numpy()
2022-09-15 11:46:14 +00:00
Jonas Mueller 7ccdb5491f Add keras wrapper to docs (#443)
* Delete huggingface_keras_classifier.py

* Update keras.py

* readme language, remove huggingfacekerasclassifier

* language improvements

* reorder modules

* make keras.py appear in docs
2022-09-15 00:47:31 -07:00
Ulyana 61f650e357 Merge pull request #426 from ulya-tkch/ulya-outlier-array-like
Updated labels to allow array_like
2022-09-14 21:21:33 -07:00
Elías Snorrason fd50f6b9c6 Deploy docs for token classification module (#438)
* docs: 📝 add usage example for get_sentence

Also remove types in docstrings.

* docs: 📝 add usage examples for filter_sentence

* docs: 📝 add page for internal.token_classification_utils

* docs: 📝 remove name of return variable

auto-tagging won't work correctly for the return value if it's not a tuple

* 📝 add pages for modules in cleanlab.token_classification

* fix indentation

* 📝 add token classification api to toctree

* 🎨 format docstrings

* 📝 add usage examples

* update example comment

* 📝 add usage examples

* 📝 add return variable name in docstring

* 📝 remove some hard-coded params types in rank module

Keep more complex parameters hard-coded for now. E.g. "enum"-like parameters.

* 🎨 remove indentation of parameters in docstrings

* 🎨 fix indentation

* colored docstring typo + formatting

* typo: occurence

* probs_merged docstring typo + formatting

Co-authored-by: Jonas Mueller <1390638+jwmueller@users.noreply.github.com>
2022-09-14 14:59:26 -07:00
Hui Wen 5603b1c8a6 Extend KerasWrapper to Functional API (#434)
* add keras functional api wrapper

* add breif docstring

* minor unittest edit

* edit unittest

* update docstring

* make unittest less strict
2022-09-14 13:10:12 -07:00
Jonas Mueller 9b78b703d5 black formatting 2022-09-14 00:00:18 -07:00
Jonas Mueller bf000d551b update labels typing to be LabelLike 2022-09-13 23:55:35 -07:00
Hui Wen 7ab4cbbf23 minor docstring edits (#436) 2022-09-13 19:01:00 -07:00
Jonas Mueller a9e3c0e5d2 emphasize features must be numeric 2022-09-13 09:37:21 -07:00
Ulyana 13d6cfc9ce Used internal function for typechecking labels 2022-09-12 16:54:07 -07:00
Elías Snorrason 9a109182b1 Update argument given_labels -> labels in token classification module (#423)
* given_labels -> labels

only applies to the argument to `display_issues`

Fixes #418

* update kwargs in test for display_issues

* apply black formatter
2022-09-11 12:38:38 -07:00
Ulyana 5243b48b00 Updated labels to array_like (list is ok) 2022-09-09 16:21:29 -07:00
Ulyana 31d2618560 Improve outliers docstring notations (#424)
* Docstring remove args test

* exclude members test

Please enter the commit message for your changes. Lines starting

* Adding params as class instance attribute

* Added autoattribute: params

* Adding autoattribute under class

* Removed no-exclude-members and addded params to members

* autoattribute with indent

* Added annotation params

* Revert to removing default params only

* Removed params as instance var listing

* Consist italics vs code syntax in docstring
2022-09-09 12:55:29 -07:00
Hui Wen d8147caded Polish multiannotator docs (#422)
* docstring formatting

* add tiebreak info

* add example link to tutorial

* add missing backticks

* minor docstring text edits

* clarify "task"

Co-authored-by: Jonas Mueller <1390638+jwmueller@users.noreply.github.com>
2022-09-09 09:15:54 -07:00
Jonas Mueller 23067aa9c6 Headers for newly added modules (#409)
* header for multiannotator module

* header for outlier module

* header for token_classification.filter

* header for token_classification.rank

* header for token_classification.summary

* header for util

* header for latent_algebra

* header for label_quality_utils

* header for token_classification_utils

* header for huggingfacekerasclassifier

* add experimental modules' dependencies to readme
2022-09-08 09:20:26 -07:00
Ulyana 9dfa001068 Implementing get_ood_scores function (#338)
* Added base structure outline for get_ood_scores()
Added base test for get_ood_scores()

* Added warning for illogical param combo

* Addressed PR comments

* Added better unit tests
* TODO: test for correctly identifying OOD example

* Moved logic from get_ood_scores to _subtract_confident_thresholds

* TODO: Is this a cleaner way of doing this? Minimal code repeat but strange change to _subtract function
* Addressed type issue

* Switched logic for getting confident thresholds

* Fixing typecheck issues wiht labels parameter being None

* Simplified helper function. Testing type

* Fixed mypy static typing issue

* Mypy typecheck logic test

* removed uncessesary imports in util file

* typechecker debugging (add assert)

* Fixed type logic and removed confident_thresholds=None return

* Added extra arg in helper func to end of func

* Added zero-index checking for label param

* Added ood examples to outlier score notebook

* Added skeleton file structure for implementing outliers

* Make adjust_pred_probs=True by default not false

* Added base Outlier class functionality

TODO:
* test_outlier.py

* Added logic tests for function

* Updated get_ood_scores to always return confident_thresholds
* Even if none were calculated (then return is None)

* Added warning for fit that doesn't calculate confident_thresholds

* Moved get_outlier_scores and get_ood_scores to outlier.py

* Changed param dicts to dicts

* Added docstring to outlier.py

* Added proper return types

* Fixed mypy typing issues

* Switched outliers -> features; ood -> predictions naming conv

* Switched docstring to stem from fit and score functions

* Changed return of helper functions

* Fixed tutorials notebook to use OutOfDistribution class

* Moved imports to top of file

* Added option for different knn objects, addressed pr comments

* Switched params arg to init only

* Addressed PR comment for notebook, cleared notebook

* Fixed PR comments, wording.

* Testing relative links on build

* Changed ood_pred_probs scores to reflect 0 = most ood 1 = least

* Added MLP for detection outliers with pred_probs

* Fixed typos

* Added MLP Import

* Improved warning when fit call unnecessary

* Changed referenced to params dict in warnings/errors

* Added bagging+MLP classifier into notebook

* Reverted tutorial wording

* OOD tutorial improvements

* cleanup OOD documentation

* adopting->using

Co-authored-by: Jonas Mueller <1390638+jwmueller@users.noreply.github.com>
2022-09-07 10:52:55 -07:00
Jonas Mueller 8323a0f0ac explain pred_probs vs clf 2022-09-06 22:13:58 -07:00
Elías Snorrason 8371edffc9 🐛 escape special regex characters (#404)
Fixes #403
2022-09-06 09:28:59 -07:00
Elías Snorrason 9f030a65ac Cleanup-summary (#396)
* 🎨 remove wildcard imports

* 🏷️ review type annotations in display_issues

Restrict nested lists with `List`. Keep unrestricted lists as `list`. Remove hard-coded tags from docstrings, should be auto-tagged in later PR.

* ♻️ use `isinstance` for type-check at runtime

* 🏷️ review type annotations in common_label_issues and filter_by_token

Remove hard-coded tags in docstrings. Should be auto-tagged in later PR.

*  improve test coverage of display issues

No part of the function is easily testable except ensuring it completes exection. Some parts handle edge cases that were never reached during testing.

*  parametrize tests for coverage on common_label_issues and filter_by_token
2022-09-05 17:21:26 -07:00
Elías Snorrason 71521e90d3 Match token/s in color_sentence (#397)
*  search tokenized sentence for coloring

Searches through the list of tokens before trying to match substrings. Thanks for this code suggestion Eric!

* 🚧 fix signature in all calls to color_sentence

*  update color_sentence test after changing its api

(sentence, word) -> (word, tokens)

*  use regex for coloring tokens in sentence

Find word boundaries with regex, use builtin replace() as fallback w/o boundaries.

Closes #288

* 🚑 invert fallback condition

Use replace if NO substitutions were made with regex.
2022-09-05 16:30:29 -07:00
Elías Snorrason afa217cb4a Fix typing for find_label_issues (#391) 2022-09-03 12:30:07 -07:00
Elías Snorrason c884dc5171 Cleanup token_classification.rank module (#393)
*  add test fixture for get_label_quality_scores

*  test softmin_sentence_score

include test cases for temperature limits

* ♻️ cleanup softmin_sentence_score

Remove unused keyword-only args, Fix tag in docstring, Change format of nested functions.

*  specialize edge-case temperature=inf in softmin_sentence_score

* ♻️ simplify temperature lookup

* ♻️ cleanup get_label_quality_scores

Remove unused args/variables. Update parameter list in docstring. Rename parameter of inner function. Function always returns a tuple.

* 🏷️ tag token_scores as optional

*  test raised error

* 🩹 skip untestable elif statement

the elif statement only gets partial coverage because it can't evaluate to False due to the `assert sentence_score_method` at the start of the function
2022-09-02 18:26:07 -07:00
Elías Snorrason 6ec5b173dd Cleanup token classification utils (#390)
* 🏷️ restrict parameters for list types

* 🐛 only process characters in input token

Example: process_token("Cleanlab", [("C", "a"), ("a", "C")]) should return "aleCnlCb", not "CleCnlCb".

*  use all sentences in test_get_sentence

*  add test cases to test_filter_sentence

*  extent test cases in test_mapping

* 📝 clean up docstrings

Restrict arg types based on docstrings. Fix punctuation and typos. Add examples to docstring.

*  split tests for filter_sentence

*  extend test_merge_probs

*  test merge_probs with ignored/normalized columns in probs

*  extend test cases for get_sentences

* ⚰️ remove unused pandas import

* 🏷️ pass strict mypy check

We ignore np.max as it is untyped.

No issues found in token_classification_utils.py by running
```
mypy --install-types --non-interactive --strict cleanlab/internal/token_classification_utils.py
```

* 👷 add strict type-checking in CI

* 💚 use strict type-check for single file

*  remove strict type check in CI

* refactor: 🏷️ use np.ndarray type instead of npt.NDArray

*  go back to generic np.ndarray type

* ♻️ always return tuple in filter_sentence

Remove unused argument+docstring. Simplify relevant unit tests.

* 🔥 resolve comments on typing

Remove ignore-comments. Remove duplicate tag in docstring. Remove unused imports.

* 🔥 remove duplicate tag in docstring
2022-09-01 17:07:39 -07:00
Hui Wen 82096cbe36 Change verbose functionality in multiannotator functions (#389)
* calculate most likely class error from subset

* use verbose to control warning prints

* clip minimum to 1e-6 to prevent division by zero

* add docstring
2022-08-31 11:07:23 -07:00
Jonas Mueller 31d4370701 Add missing docs pages (#381)
* add files to show docs for recent source code

* temp delete audio tutorial for docs on M1

* black formatting
2022-08-31 02:28:45 -07:00
Hui Wen 960c2b4ac1 CL functionality for multiannotator data (#333)
* setup multiannotator functionality

* add docstring

* add unittests

* edit get label quality with nan helper func

* docstring edits

* handle non overlapping annotators in get_annotator_agreement_with_annotators

* return NaN annotator quality scores for non-overlapping annotators

* add unittest

* add unittests for get_consensus_label tiebreaks

* np.array -> np.ndarray

* add new annotator quality method

* docstring edits

* address comments, docstring changes

* add method to compute improved consensus labels

* separate detailed_label_quality return

* elif statement typo

* changed get_majority_vote_label

* add 'best_quality' as a consensus method

* change lqs kwargs naming

* change lqs kwargs naming

* change unittest function names

* docstring edits

* change get_worst_class to return class with lowest agreement with consensus

* edit method to get annotator lqs, change quality_of_consensus -> consensus_quality_score

* remove unnecessary args

* satisfy mypy checks

* fix mypy issue

* add unittests

* reshuffled order of functions

* address comments

* docstring edit

* change return to always return dict

* add clipping to prevent negative pred_probs

* add tutorial

* add multiannotator to tutorial index

* add newline

* add tiebreaks for best_quality labels and worst_class

* change auto method name to crowdlab

* fix indexing for non numeric anno names

* add test for nonnumeric anno names

* update unittest

* address comments [partially complete]

* edit metadata

* missing /details tag

* bugfix to allow pd Int64 types

* update tutorial

* address comments
2022-08-30 11:29:06 -07:00
Eric Wang 1bad2f82a2 Adding functionality for cleanlab to find label errors in token classification datasets (#347)
* add token_classification functionality

* add typing

* fix typing

* add typing

* fixed typing and black

* fix typing
2022-08-30 09:17:07 -07:00
Curtis G. Northcutt 3fb4133a5c np.array to np.ndarray 2022-08-09 03:30:57 -04:00
Curtis G. Northcutt 72d6c73a94 Clarify shapes of matrices in cj_multi_label 2022-08-09 03:25:03 -04:00
Ulyana c0fe76c098 Changed all docstring instances of np.array to np.ndarray (#336)
* Changed all instances of np.array in docstring to np.ndarray

* np.array is NOT a proper class name it is just a function to
  create np.ndarrays and therefore should not be parameter class

* Black formatting compliance
2022-08-08 23:30:12 -07:00
Hui Wen e9db4bc30a allow missing classes in assert_valid_class_labels (#335) 2022-08-08 21:59:14 -04:00
Hui Wen b96a78405e allow missing classes in get_label_quality_scores (#334) 2022-08-08 13:23:01 -07:00
Jonas Mueller dc515c93f3 Update filter.py (#331) 2022-08-03 03:06:07 -07:00
Jonas Mueller 878244f904 Re-order find_label_issues args for better clarity (#329)
* findlabelissues doc clarifications + arg order

* clarify return_indices_ranked_by specifies return

* moved multi_label up higher. kept ranked_by at top

Co-authored-by: Curtis G. Northcutt <curtis.northcutt@gmail.com>
2022-07-29 17:15:46 -04:00
Jonas Mueller b93fdebf30 Add compatibility for tensorflow and pytorch Dataset objects (#311)
* validation_func docstring

* torch,tf compatibility+tests

* keras test

* skip tests if python < 3.7

* pytorch numpy int bug on windows

* make tensorflow test work on windows

* move tf env variable setting

* pytorch test increase epochs

* install cpu-tensorflow on windows CI

* torch test optimizer to adam

* fix bugs in shuffled TF dataset

* dummy unit test for TF on windows

* dummy code for TF windows testing

* deal with np.int bug on windows

* remove windows debugging code

* docstrings for new functionality

* address merge conflicts

* reformat after merge

* addressed comments
2022-07-27 21:42:13 -07:00
Elías Snorrason 8b60a381e4 validation.py: Annotate function args and return values (#317)
* 🏷️ annotate function args and return values

Starting with the validation module:

- I think (X, y) might need some custom Union type to handle both numpy arrays and pandas dataframe, etc.
- All of the "assert" functions return None.

Ref #307

* refactor: 🏷️ swap npt.NDArray -> np.ndarray

np.ndarray seems more consistent with the rest of the repo.
Maybe it's necessary to go back to npt.NDArray when disallowing generics?

See numpy docs: https://numpy.org/devdocs/reference/typing.html#numpy.typing.NDArray

* refactor: 🔥 remove unused import

* 🏷️ unconstrain X input types

* 🐛 handle label type issues

- Have to restrict the output of labels_to_array to pass mypy checks.
- Returning the values of pd.Series isn't type-stable.

* 🏷️ include np.generic in arg-type union

* test:  test labels_to_array

* 🏷️ add type aliases for X and y

* 🚨 ignore type-checks for pandas indexing assertions

CI typechecker runs on Python 3.10 which gives this error:

'cleanlab/internal/validation.py:125: error: No overload variant of "__getitem__" of "_iLocIndexerSeries" matches argument type "List[int]"'

It should be fine to let mypy ignore these expressions as they don't return anything.

* 🥅 specify errors to ignore

"type: ignore" doesn't pass strict mypy type-checks unless the specific errors are provided

* 🏷️ annotate label series to array
2022-07-26 12:58:37 -07:00
Elías Snorrason cecaf7aec6 Add y argument as alternative to labels in CleanLearning.fit() (#322)
* 🗑️ change labels arg -> y in CleanLearning.fit()

Set `label` as an optional keyword-only argument.
Anyone still using it in this method should get a deprecation warning.

Fixes #281

* 📝 add note for y/labels in docstring

* 🥅 make y an optional positional arg.

Should now resolve deprecated signatures.

* 📝 labels -> y in module docstring

*  revert "label -> y deprecation"

This reverts commit ab319a0cca2cec715a84eb5f628bbab7706c5f9c.
This reverts commit 1b739002d848e1f0acb6390a666f6e695e25fcaa.
This reverts commit 88bb6c3bcca298dab414c3cb20101783d78d35d1.
This reverts commit d988e3c3932107e779598d02d8f16d7e6671e9e7.

*  add y alias for labels

Resolves #281
2022-07-26 00:59:10 -07:00
Jonas Mueller a0e1227ae5 Allow KNN object to be returned by get_outlier_scores, Improved Tutorial (#319)
* knn return, improved tutorial

* typing fix for tuple

* add timm to docs-requirements

* language improvements

* declare typing of outlier_scores
2022-07-25 12:40:58 -07:00
Jonas Mueller a4f51327db fix KNN default k-value bugs (#315) 2022-07-21 15:00:51 -07:00
Hui Wen 6c6c13664e Standardize naming on K, num_classes and N, num_examples (#312)
* update N in classification.py

* minor docstring changes on K-1 classes

* use K in shape

* minor grammar fixes

* docs language improvements

Co-authored-by: Jonas Mueller <1390638+jwmueller@users.noreply.github.com>
2022-07-18 18:50:17 -07:00
Ulyana fef76ba357 Added support to build KNN graph with only training data (#305)
* Added support to build KNN graph with only training data
- Added default classifier for get_knn_distance_ood_scores()

* Added unit test for checking default KNN model is used when nbrs=None

* Changed default num neighbors from 10 to K.

* Changed unit test to check score sums

* Fixed k=15

* Added support to build KNN graph with only training data

- Added default classifier for get_knn_distance_ood_scores()

- Added unit test for checking default KNN model is used when nbrs=None

- Changed default num neighbors from 10 to K.

- Changed unit test to check score sums

* Improved code readibility, extended unit test to check for default k

* Changed naming convention from get_knn_distance_ood_scores to get_outlier_scores

- Changed nbrs to knn
- Improved unit test readability

* Made unit test more robust to check if user-set value is passed

* changed classifier -> estimator
* fixed test warning handle

* Updated function headers to better definition

* Improved header writing added functionality to avoid training/testing with identical features

* Updated docstring, updated handling of features=None and test for it

* Added ValueError for k>len(features) and test to catch ValueError

* Updated argument types to Optional, added runtime typecheck.

* Added unit test to check TypeError

* Changed Exception type thrown when knn=None, features=None

* TypeError to ValueError

* Reversed scoring for outlier severity
* Added test to check t parameter
* Added t parameter for global rescaler

* Improved function definition concerning 't' parameter

* Fixed tests
* Removed repeated calls
* Added assertion to make sure X_ood is always smallest outlier score

* Improved logic for checking X_ood has the smallest score
2022-07-14 10:36:10 -07:00