diff --git a/.flake8 b/.flake8 deleted file mode 100644 index b91a117..0000000 --- a/.flake8 +++ /dev/null @@ -1,7 +0,0 @@ -[flake8] -max-line-length = 120 -ignore = - E203,E501,F841,W503 -per-file-ignores = - __init__.py: F401 - ./learnware/utils/import_utils.py: F401 \ No newline at end of file diff --git a/.gitee/ISSUE_TEMPLATE/bug-report.yml b/.gitee/ISSUE_TEMPLATE/bug-report.yml new file mode 100644 index 0000000..06d15e6 --- /dev/null +++ b/.gitee/ISSUE_TEMPLATE/bug-report.yml @@ -0,0 +1,20 @@ +name: "\U0001F41B 错误报告" +description: 提交错误报告以帮助我们改进北冥坞系统 +body: +- type: textarea + id: bug-detail + attributes: + label: 错误信息 + description: 请描述你所遇到的错误,并且提供用于复现错误的代码或者运行截图. + placeholder: 错误描述和复现方法. + validations: + required: true + + - type: textarea + id: env-info + attributes: + label: 环境配置 + description: 请与我们分享你的环境配置信息. + placeholder: learnware 版本, 使用的平台, python 版本, 等等. + validations: + required: true \ No newline at end of file diff --git a/.gitee/ISSUE_TEMPLATE/documentation.yml b/.gitee/ISSUE_TEMPLATE/documentation.yml new file mode 100644 index 0000000..bacc8e9 --- /dev/null +++ b/.gitee/ISSUE_TEMPLATE/documentation.yml @@ -0,0 +1,12 @@ +name: "\U0001F4D6 文档" +description: 提交与文档相关的问题 +labels: [ "documentation" ] +body: + - type: textarea + id: description + validations: + required: true + attributes: + label: 具体描述 + description: | + 请清晰地描述你的问题. \ No newline at end of file diff --git a/.gitee/ISSUE_TEMPLATE/feature-request.yml b/.gitee/ISSUE_TEMPLATE/feature-request.yml new file mode 100644 index 0000000..e4b2cad --- /dev/null +++ b/.gitee/ISSUE_TEMPLATE/feature-request.yml @@ -0,0 +1,19 @@ +name: "\U0001F680 功能建议" +description: 提交关于 Learnware 新功能的建议 +labels: [ "feature" ] +body: + - type: textarea + id: feature-request + validations: + required: true + attributes: + label: 功能描述 + description: | + 对所建议功能的清晰且简洁的描述. 如果功能和其他论文、代码或者 Issues 相关, 可以提供相应的链接. + + - type: textarea + id: contribution + attributes: + label: 你的贡献 + description: | + 你是否可以提供帮助, 例如提交 PR? diff --git a/.gitee/ISSUE_TEMPLATE/question.yml b/.gitee/ISSUE_TEMPLATE/question.yml new file mode 100644 index 0000000..7c6e7f6 --- /dev/null +++ b/.gitee/ISSUE_TEMPLATE/question.yml @@ -0,0 +1,12 @@ +name: "\U00002753 问题 & 帮助" +description: 是否有相关问题? 我们可以提供帮助 +labels: [ "question" ] +body: + - type: textarea + id: question + validations: + required: true + attributes: + label: 具体描述 + description: | + 我们真诚地建议你仔细阅读我们项目的文档. 之后如果仍有相关困惑, 请在此问题下清晰地描述你的问题. \ No newline at end of file diff --git a/.gitee/PULL_REQUEST_TEMPLATE.md b/.gitee/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..cdb712c --- /dev/null +++ b/.gitee/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,17 @@ + + +## 描述 + + +## 如何测试此 PR? +请全面测试您的更改,并附上测试结果的截图(如果适用)。 + + +- [ ] 请通过在 learnware 的上级目录下运行 `pytest tests/test_workflow` 来通过测试。 +- [ ] 如果您添加了新功能,请在您自己的测试脚本上测试该功能。 + +## 更改的类型 + +- [ ] 此 PR 修复了 bug +- [ ] 此 PR 添加了新功能 +- [ ] 此 PR 更新了文档或修复了拼写错误 diff --git a/.github/ISSUE_TEMPLATE/bug-report.yml b/.github/ISSUE_TEMPLATE/bug-report.yml new file mode 100644 index 0000000..6a7b2fe --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug-report.yml @@ -0,0 +1,20 @@ +name: "\U0001F41B Bug Report" +description: Submit a bug report to help us improve learnware +body: + - type: textarea + id: bug-detail + attributes: + label: Bug Detail + description: Please report the bug in detail or provide a code sample that reproduces the problem you ran into. + placeholder: bug detail and reproduction. + validations: + required: true + + - type: textarea + id: runtime-environment + attributes: + label: Runtime Environment + description: Please share your environment setting with us. + placeholder: learnware version, platform, python version, ... + validations: + required: true \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/documentation.yml b/.github/ISSUE_TEMPLATE/documentation.yml new file mode 100644 index 0000000..e2df1bd --- /dev/null +++ b/.github/ISSUE_TEMPLATE/documentation.yml @@ -0,0 +1,12 @@ +name: "\U0001F4D6 Documentation" +description: Report an issue related to documentation +labels: [ "documentation" ] +body: + - type: textarea + id: description + validations: + required: true + attributes: + label: Description + description: | + A clear description of the issue related to documentation. \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/feature-request.yml b/.github/ISSUE_TEMPLATE/feature-request.yml new file mode 100644 index 0000000..86b5e0f --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature-request.yml @@ -0,0 +1,20 @@ +name: "\U0001F680 Feature request" +description: Submit a proposal/request for a new learnware feature +labels: [ "feature" ] +body: + - type: textarea + id: feature-request + validations: + required: true + attributes: + label: Feature request + description: | + A clear and concise description of the feature proposal. If this is related to papers, codes, or other issues, please link here. + + + - type: textarea + id: contribution + attributes: + label: Your Contribution + description: | + Is there any way that you could help, e.g. by submitting a PR? diff --git a/.github/ISSUE_TEMPLATE/question.yml b/.github/ISSUE_TEMPLATE/question.yml new file mode 100644 index 0000000..f8d2483 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/question.yml @@ -0,0 +1,12 @@ +name: "\U00002753 Questions & Help" +description: Have some questions? We can offer help +labels: [ "question" ] +body: + - type: textarea + id: question + validations: + required: true + attributes: + label: Description + description: | + We sincerely suggest you to carefully read the [documentation](http://learnware.readthedocs.io/) of our library. After that, if you still feel puzzled, please describe the question clearly under this issue. \ No newline at end of file diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..0691d27 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,15 @@ + + +## Description + + +## How has his PR been tested? + +- [ ] Please pass the test by running `pytest tests/test_workflow` under upper directory of learnware. +- [ ] If you add new features, please test new features on your own test scirpts. + +## Types of changes + +- [ ] This PR fixes bugs +- [ ] This PR adds new features +- [ ] This PR update documentations or fixes typo diff --git a/.github/labeler.yml b/.github/labeler.yml new file mode 100644 index 0000000..bd31eaa --- /dev/null +++ b/.github/labeler.yml @@ -0,0 +1,6 @@ +documentation: +- 'docs/**/*' +- '**/*.md' + +pending: +- any: ['**/*', '!docs/**/*', '!**/*.md'] diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml new file mode 100644 index 0000000..08cd644 --- /dev/null +++ b/.github/release-drafter.yml @@ -0,0 +1,24 @@ +name-template: 'v$RESOLVED_VERSION 🌈' +tag-template: 'v$RESOLVED_VERSION' +categories: + - title: '🌟 New Feature' + labels: + - 'feature' + - 'enhancement' + - title: '🐛 Fixed Bug' + labels: + - 'fix' + - 'bugfix' + - 'bug' + - title: '📚 Documentation' + label: + - 'doc' + - 'documentation' + - title: '🧹 Maintenance' + label: + - 'maintenance' +change-template: '- $TITLE @$AUTHOR (#$NUMBER)' +template: | + ## Changes + + $CHANGES \ No newline at end of file diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml new file mode 100644 index 0000000..99aacae --- /dev/null +++ b/.github/workflows/labeler.yml @@ -0,0 +1,15 @@ +name: Add Label +on: +- pull_request_target + +jobs: + label: + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: write + + steps: + - uses: actions/labeler@v4 + with: + repo-token: "${{ secrets.GITHUB_TOKEN }}" diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml new file mode 100644 index 0000000..7fd91d1 --- /dev/null +++ b/.github/workflows/python-publish.yml @@ -0,0 +1,79 @@ +# This workflows will upload a Python Package using Twine when a release is created +# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries + +name: Upload Python Package + +on: + release: + types: [published] + +jobs: + deploy_with_source: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.8' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install build twine + - name: Build package + run: python -m build --sdist + - name: Build and publish + env: + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + run: | + twine upload dist/learnware-*.tar.gz + + deploy_with_bdist_wheel: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [windows-latest] + python-version: ['3.8', '3.9', '3.10', '3.11'] + + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install setuptools wheel twine + - name: Build wheel on ${{ matrix.os }} + run: | + python setup.py bdist_wheel + - name: Build and publish + env: + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + run: | + twine upload dist/learnware-*.whl + + deploy_with_manylinux: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Build wheel on Linux + uses: RalfG/python-wheels-manylinux-build@v0.7.1-manylinux2010_x86_64 + with: + python-versions: 'cp38-cp38 cp39-cp39 cp310-cp310 cp311-cp311' + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.8' + - name: Install dependencies + run: | + pip install twine + - name: Build and publish + env: + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + run: | + twine upload dist/learnware-*-manylinux*.whl \ No newline at end of file diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml new file mode 100644 index 0000000..c842f64 --- /dev/null +++ b/.github/workflows/release-drafter.yml @@ -0,0 +1,16 @@ +name: Release Drafter + +on: + push: + # branches to consider in the event; optional, defaults to all + branches: + - main + +jobs: + update_release_draft: + runs-on: ubuntu-latest + steps: + # Drafts your next Release notes as Pull Requests are merged into "main" + - uses: release-drafter/release-drafter@v5.11.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/install_learnware_with_pip.yaml b/.github/workflows/test_learnware_with_pip.yaml similarity index 89% rename from .github/workflows/install_learnware_with_pip.yaml rename to .github/workflows/test_learnware_with_pip.yaml index 350ed1d..c59a63f 100644 --- a/.github/workflows/install_learnware_with_pip.yaml +++ b/.github/workflows/test_learnware_with_pip.yaml @@ -1,4 +1,4 @@ -name: Test leanrnware from pip +name: Test learnware with pip on: push: @@ -41,8 +41,8 @@ jobs: - name: Install learnware run: | - conda run -n learnware python -m pip install learnware + conda run -n learnware python -m pip install learnware[full] - name: Test workflow run: | - conda run -n learnware python -m pytest tests/test_workflow/ + conda run -n learnware python -m pytest tests/test_workflow/test_hetero_workflow.py diff --git a/.github/workflows/install_learnware_with_source.yaml b/.github/workflows/test_learnware_with_source.yaml similarity index 85% rename from .github/workflows/install_learnware_with_source.yaml rename to .github/workflows/test_learnware_with_source.yaml index 02cba9e..13b6ac9 100644 --- a/.github/workflows/install_learnware_with_source.yaml +++ b/.github/workflows/test_learnware_with_source.yaml @@ -1,4 +1,4 @@ -name: Test leanrnware from source code +name: Test learnware on: push: @@ -42,12 +42,12 @@ jobs: - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names - conda run -n learnware python -m flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + conda run -n learnware python -m flake8 . --ignore=E203,E501,F841,W503 - name: Install learnware run: | - conda run -n learnware python -m pip install . + conda run -n learnware python -m pip install .[full] - name: Test workflow run: | - conda run -n learnware python -m pytest tests/test_workflow/ \ No newline at end of file + conda run -n learnware python -m pytest tests/test_workflow/test_hetero_workflow.py \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f8443a1..0585f94 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,7 +6,7 @@ repos: args: ["-l 120"] - repo: https://github.com/PyCQA/flake8 - rev: 4.0.1 + rev: 6.1.0 hooks: - id: flake8 - args: ["--count", "--select=E9,F63,F7,F82", "--show-source", "--statistics"] \ No newline at end of file + args: ["--ignore=E203,E501,F841,W503"] \ No newline at end of file diff --git a/CHANGES.rst b/CHANGES.rst index 4f9529f..75fc6d8 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,7 +1,7 @@ Changelog ========= -Here you can see the full list of changes between each Learnware Market release. +Here you can see the full list of changes between ``learnware`` release. -Version 0.1.0 -------------- -This is the initial release of Learnware Market. +Version 0.3.0 +--------------- +This is the first public release of ``learnware`` package. diff --git a/README.md b/README.md index f05bb41..543c521 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@
- +

@@ -11,26 +11,26 @@ Platform - - Test - PypI Versions + + PyPI Downloads + Documentation Status - + License

-

-

- English | - 中文 -

-

+

+

+ 中文 | + English +

+

# Introduction @@ -48,35 +48,49 @@ In addition, the `learnware` package serves as the engine for the [Beimingwu Sys A learnware consists of a high-performance machine learning model and specifications that characterize the model, i.e., "Learnware = Model + Specification". These specifications, encompassing both semantic and statistical aspects, detail the model's functionality and statistical information, making it easier for future users to identify and reuse these models. -The need for Learnware arises due to challenges in machine learning, such as the need for extensive training data, advanced techniques, continuous learning, catastrophic forgetting, and data privacy issues. Although there are many efforts focusing on one of these issues separately, they are entangled, and solving one problem may exacerbate others. The learnware paradigm aims to address many of these challenges through a unified framework. Its benefits are listed as follows. +
+ +
-| Benefit | Description | -| ---- | ---- | -| Lack of training data | Strong models can be built with small data by adapting well-performed learnwares. | -| Lack of training skills | Ordinary users can obtain strong models by leveraging well-performed learnwares instead of building models from scratch. | -| Catastrophic forgetting | Accepted learnwares are always stored in the learnware market, retaining old knowledge. | -| Continual learning | The learnware market continually enriches its knowledge with constant submissions of well-performed learnwares. | -| Data privacy/ proprietary | Developers only submit models, not data, preserving data privacy/proprietary. | -| Unplanned tasks | Open to all legal developers, the learnware market can accommodate helpful learnwares for various tasks. | -| Carbon emission | Assembling small models may offer good-enough performance, reducing interest in training large models and the carbon footprint. | - -The learnware paradigm consists of two distinct stages: +The above diagram illustrates the learnware paradigm, which consists of two distinct stages: - `Submitting Stage`: Developers voluntarily submit various learnwares to the learnware market, and the system conducts quality checks and further organization of these learnwares. - `Deploying Stage`: When users submit task requirements, the learnware market automatically selects whether to recommend a single learnware or a combination of multiple learnwares and provides efficient deployment methods. Whether it’s a single learnware or a combination of multiple learnwares, the system offers convenient learnware reuse interfaces. +## Framework and Infrastructure Design +
- +
-## Learnware Package Design +The architecture is designed based on the guidelines including _decoupling_, _autonomy_, _reusability_, and _scalability_. The above diagram illustrates the framework from the perspectives of both modules and workflows. + +- At the workflow level, the `learnware` package consists of `Submitting Stage` and `Deploying Stage`. + +
+ +| Module | Workflow | +| ---- | ---- | +| `Submitting Stage` | The developers submit learnwares to the learnware market, which conducts usability checks and further organization of these learnwares. | +| `Deploying Stage` | The learnware market recommends learnwares according to users’ task requirements and provides efficient reuse and deployment methods. | + +
+ +- At the module level, the `learnware` package is a platform that consists of `Learnware`, `Market`, `Specification`, `Model`, `Reuse`, and `Interface` modules. + +
+ +| Module | Description | +| ---- | ---- | +| `Learnware` | The specific learnware, consisting of specification module, and user model module. | +| `Market` | Designed for learnware organization, identification, and usability testing. | +| `Specification` | Generating and storing statistical and semantic information of learnware, which can be used for learnware search and reuse. | +| `Model` | Including the base model and the model container, which can provide unified interfaces and automatically create isolated runtime environments. | +| `Reuse` | Including the data-free reuser, data-dependent reuser, and aligner, which can deploy and reuse learnware for user tasks. | +| `Interface` | The interface for network communication with the `Beimingwu` backend.| -
-
-At the workflow level, the `learnware` package consists of `Submitting Stage` and `Deploying Stage`. -At the module level, the `learnware` package is a platform that consists of above components. The components are designed as loose-coupled modules and each component could be used stand-alone. # Quick Start @@ -105,7 +119,7 @@ In the `learnware` package, each learnware is encapsulated in a `zip` package, w - `stat.json`: the statistical specification of the learnware. Its filename can be customized and recorded in learnware.yaml. - `environment.yaml` or `requirements.txt`: specifies the environment for the model. -To facilitate the construction of a learnware, we provide a [Learnware Template](https://www.bmwu.cloud/static/learnware-template.zip) that users can use as a basis for building their own learnware. We've also detailed the format of the learnware `zip` package in [Learnware Preparation](docs/workflows/upload:prepare-learnware). +To facilitate the construction of a learnware, we provide a [Learnware Template](https://www.bmwu.cloud/static/learnware-template.zip) that users can use as a basis for building their own learnware. We've also detailed the format of the learnware `zip` package in [Learnware Preparation](https://learnware.readthedocs.io/en/latest/workflows/upload.html#prepare-learnware). ## Learnware Package Workflow @@ -147,7 +161,7 @@ After defining the semantic specification, you can upload your learnware using a demo_market.add_learnware(zip_path, semantic_spec) ``` -Here, `zip_path` is the directory of your learnware `zip` package. +Here, `zip_path` is the file path of your learnware `zip` package. ### Semantic Specification Search @@ -169,7 +183,7 @@ print(single_result) If you decide in favor of providing your own statistical specification file, `stat.json`, the `Learnware Market` can further refine the selection of learnwares from the previous step. This second-stage search leverages statistical information to identify one or more learnwares that are most likely to be beneficial for your task. -For example, the code below executes learnware search when using Reduced Set Kernel Embedding as the statistical specification: +For example, the code below executes learnware search when using Reduced Kernel Mean Embedding as the statistical specification: ```python import learnware.specification as specification @@ -215,20 +229,20 @@ reuse_ensemble = AveragingReuser(learnware_list=mixture_item.learnwares) ensemble_predict_y = reuse_ensemble.predict(user_data=test_x) ``` -We also provide two methods when the user has labeled data for reusing a given list of learnwares: `EnsemblePruningReuser` and `FeatureAugmentReuser`. Substitute `test_x` in the code snippet below with your testing data, and substitute `train_X, train_y` with your training labeled data, and you're all set to reuse learnwares: +We also provide two methods when the user has labeled data for reusing a given list of learnwares: `EnsemblePruningReuser` and `FeatureAugmentReuser`. Substitute `test_x` in the code snippet below with your testing data, and substitute `train_x, train_y` with your training labeled data, and you're all set to reuse learnwares: ```python from learnware.reuse import EnsemblePruningReuser, FeatureAugmentReuser # Use ensemble pruning reuser to reuse the searched learnwares to make prediction reuse_ensemble = EnsemblePruningReuser(learnware_list=mixture_item.learnwares, mode="classification") -reuse_ensemble.fit(train_X, train_y) -ensemble_pruning_predict_y = reuse_ensemble.predict(user_data=data_X) +reuse_ensemble.fit(train_x, train_y) +ensemble_pruning_predict_y = reuse_ensemble.predict(user_data=test_x) # Use feature augment reuser to reuse the searched learnwares to make prediction reuse_feature_augment = FeatureAugmentReuser(learnware_list=mixture_item.learnwares, mode="classification") -reuse_feature_augment.fit(train_X, train_y) -feature_augment_predict_y = reuse_feature_augment.predict(user_data=data_X) +reuse_feature_augment.fit(train_x, train_y) +feature_augment_predict_y = reuse_feature_augment.predict(user_data=test_x) ``` ### Auto Workflow Example @@ -237,6 +251,8 @@ The `learnware` package also offers automated workflow examples. This includes p # Experiments and Examples +We build various types of experimental scenarios and conduct extensive empirical study to evaluate the baseline algorithms for specification generation, learnware identification, and reuse on tabular, image, and text data. + ## Environment For all experiments, we used a single Linux server. Details on the specifications are listed in the table below. All processors were used for training and evaluating. @@ -251,89 +267,84 @@ For all experiments, we used a single Linux server. Details on the specification ## Tabular Scenario Experiments -### Datasets - -Our study involved three public datasets in the sales forecasting field: [Predict Future Sales (PFS)](https://www.kaggle.com/c/competitive-data-science-predict-future-sales/data), [M5 Forecasting (M5)](https://www.kaggle.com/competitions/m5-forecasting-accuracy/data), and [Corporacion](https://www.kaggle.com/competitions/favorita-grocery-sales-forecasting/data). - -We applied various pre-processing methods to these datasets to enhance the richness of the data. After pre-processing, we first divided each dataset by store and then split the data for each store into training and test sets. Specifically: - -- For PFS, the test set consisted of the last month's data from each store. -- For M5, we designated the final 28 days' data from each store as the test set. -- For Corporacion, the test set was composed of the last 16 days of data from each store. +On various tabular datasets, we initially evaluate the performance of identifying and reusing learnwares from the learnware market that share the same feature space as the user's tasks. Additionally, since tabular tasks often come from heterogeneous feature spaces, we also assess the identification and reuse of learnwares from different feature spaces. -In the submitting stage, the Corporacion dataset's 55 stores are regarded as 165 uploaders, each employing one of three different feature engineering methods. For the PFS dataset, 100 uploaders are established, each using one of two feature engineering approaches. These uploaders then utilize their respective stores' training data to develop LightGBM models. As a result, the learnware market comprises 265 learnwares, derived from five types of feature spaces and two types of label spaces. +### Settings -Based on the specific design of user tasks, our experiments were primarily categorized into two types: +Our study utilize three public datasets in the field of sales forecasting: [Predict Future Sales (PFS)](https://www.kaggle.com/c/competitive-data-science-predict-future-sales/data), [M5 Forecasting (M5)](https://www.kaggle.com/competitions/m5-forecasting-accuracy/data), and [Corporacion](https://www.kaggle.com/competitions/favorita-grocery-sales-forecasting/data). To enrich the data, we apply diverse feature engineering methods to these datasets. Then we divide each dataset by store and further split the data for each store into training and test sets. A LightGBM is trained on each Corporacion and PFS training set, while the test sets and M5 datasets are reversed to construct user tasks. This results in an experimental market consisting of 265 learnwares, encompassing five types of feature spaces and two types of label spaces. All these learnwares have been uploaded to the [Beimingwu system](https://bmwu.cloud/). -- **homogeneous experiments** are designed to evaluate performance when users can reuse learnwares in the learnware market that have the same feature space as their tasks (homogeneous learnwares). This contributes to showing the effectiveness of using learnwares that align closely with the user's specific requirements. +### Baseline algorithms +The most basic way to reuse a learnware is Top-1 reuser, which directly uses the single learnware chosen by RKME specification. Besides, we implement two data-free reusers and two data-dependent reusers that works on single or multiple helpful learnwares identified from the market. When users have no labeled data, JobSelector reuser selects different learnwares for different samples by training a job selector classifier; AverageEnsemble reuser uses an ensemble method to make predictions. In cases where users possess both test data and limited labeled training data, EnsemblePruning reuser selectively ensembles a subset of learnwares to choose the ones that are most suitable for the user’s task; FeatureAugment reuser regards each received learnware as a feature augmentor, taking its output as a new feature and then builds a simple model on the augmented feature set. JobSelector and FeatureAugment are only effective for tabular data, while others are also useful for text and image data. -- **heterogeneous experiments** aim to evaluate the performance of identifying and reusing helpful heterogeneous learnwares in situations where no available learnwares match the feature space of the user's task. This helps to highlight the potential of learnwares for applications beyond their original purpose. +### Homogeneous Cases -### Homogeneous Tabular Scenario +In the homogeneous cases, the 53 stores within the PFS dataset function as 53 individual users. Each store utilizes its own test data as user data and applies the same feature engineering approach used in the learnware market. These users could subsequently search for homogeneous learnwares within the market that possessed the same feature spaces as their tasks. -For homogeneous experiments, the 55 stores in the Corporacion dataset act as 55 users, each applying one feature engineering method, and using the test data from their respective store as user data. These users can then search for homogeneous learnwares in the market with the same feature spaces as their tasks. - -The Mean Squared Error (MSE) of search and reuse across all users is presented in the table below: +We conduct a comparison among different baseline algorithms when the users have no labeled data or limited amounts of labeled data. The average losses over all users are illustrated in the table below. It shows that unlabeled methods are much better than random choosing and deploying one learnware from the market.
| Setting | MSE | |-----------------------------------|--------| -| Mean in Market (Single) | 0.331 | -| Best in Market (Single) | 0.151 | -| Top-1 Reuse (Single) | 0.280 | -| Job Selector Reuse (Multiple) | 0.274 | -| Average Ensemble Reuse (Multiple) | 0.267 | +| Mean in Market (Single) | 0.897 | +| Best in Market (Single) | 0.756 | +| Top-1 Reuse (Single) | 0.830 | +| Job Selector Reuse (Multiple) | 0.848 | +| Average Ensemble Reuse (Multiple) | 0.816 |
-When users have both test data and limited training data derived from their original data, reusing single or multiple searched learnwares from the market can often yield better results than training models from scratch on limited training data. We present the change curves in MSE for the user's self-trained model, as well as for the Feature Augmentation single learnware reuse method and the Ensemble Pruning multiple learnware reuse method. These curves display their performance on the user's test data as the amount of labeled training data increases. The average results across 55 users are depicted in the figure below: +The figure below showcases the results for different amounts of labeled data provided by the user; for each user, we conducted multiple experiments repeatedly and calculated the mean and standard deviation of the losses; the average losses over all users are illustrated in the figure. It illustrates that when users have limited training data, identifying and reusing single or multiple learnwares yields superior performance compared to user's self-trained models.
- +
-From the figure, it's evident that when users have limited training data, the performance of reusing single/multiple table learnwares is superior to that of the user's own model. This emphasizes the benefit of learnware reuse in significantly reducing the need for extensive training data and achieving enhanced results when available user training data is limited. +### Heterogeneous Cases -### Heterogeneous Tabular Scenario +Based on the similarity of tasks between the market's learnwares and the users, the heterogeneous cases can be further categorized into different feature engineering and different task scenarios. -In heterogeneous experiments, the learnware market would recommend helpful heterogeneous learnwares with different feature spaces with the user tasks. Based on whether there are learnwares in the market that handle tasks similar to the user's task, the experiments can be further subdivided into the following two types: +#### Different Feature Engineering Scenarios -#### Cross Feature Space Experiments +We consider the 41 stores within the PFS dataset as users, generating their user data using a unique feature engineering approach that differ from the methods employed by the learnwares in the market. As a result, while some learnwares in the market are also designed for the PFS dataset, the feature spaces do not align exactly. -We designate the 41 stores in the PFS dataset as users, creating their user data with an alternative feature engineering approach that varies from the methods employed by learnwares in the market. Consequently, while the market's learnwares from the PFS dataset undertake tasks very similar to our users, the feature spaces do not match exactly. In this experimental configuration, we tested various heterogeneous learnware reuse methods (without using user's labeled data) and compared them to the user's self-trained model based on a small amount of training data. The average MSE performance across 41 users is as follows: +In this experimental setup, we examine various data-free reusers. The results in the following table indicate that even when users lack labeled data, the market exhibits strong performance, particularly with the AverageEnsemble method that reuses multiple learnwares.
| Setting | MSE | |-----------------------------------|--------| -| Mean in Market (Single) | 1.459 | -| Best in Market (Single) | 1.226 | -| Top-1 Reuse (Single) | 1.407 | -| Average Ensemble Reuse (Multiple) | 1.312 | -| User model with 50 labeled data | 1.267 | +| Mean in Market (Single) | 1.149 | +| Best in Market (Single) | 1.038 | +| Top-1 Reuse (Single) | 1.105 | +| Average Ensemble Reuse (Multiple) | 1.081 |
-From the results, it is noticeable that the learnware market still performs quite well even when users lack labeled data, provided it includes learnwares addressing tasks that are similar but not identical to the user's. In these instances, the market's effectiveness can match or even rival scenarios where users have access to a limited quantity of labeled data. -#### Cross Task Experiments +#### Different Task Scenarios + +We employ three distinct feature engineering methods on all the ten stores from the M5 dataset, resulting in a total of 30 users. Although the overall task of sales forecasting aligns with the tasks addressed by the learnwares in the market, there are no learnwares specifically designed to satisfy the M5 sales forecasting requirements. -Here we have chosen the 10 stores from the M5 dataset to act as users. Although the broad task of sales forecasting is similar to the tasks addressed by the learnwares in the market, there are no learnwares available that directly cater to the M5 sales forecasting requirements. All learnwares show variations in both feature and label spaces compared to the tasks of M5 users. We present the change curves in RMSE for the user's self-trained model and several learnware reuse methods. These curves display their performance on the user's test data as the amount of labeled training data increases. The average results across 10 users are depicted in the figure below: +In the following figure, we present the loss curves for the user's self-trained model and several learnware reuse methods. It is evident that heterogeneous learnwares prove beneficial with a limited amount of the user's labeled data, facilitating better alignment with the user's specific task.
- +
-We can observe that heterogeneous learnwares are beneficial when there's a limited amount of the user's labeled training data available, aiding in better alignment with the user's specific task. This underscores the potential of learnwares to be applied to tasks beyond their original purpose. ## Image Scenario Experiment -For the CIFAR-10 dataset, we sampled the training set unevenly by category and constructed unbalanced training datasets for the 50 learnwares that contained only some of the categories. This makes it unlikely that there exists any learnware in the learnware market that can accurately handle all categories of data; only the learnware whose training data is closest to the data distribution of the target task is likely to perform well on the target task. Specifically, the probability of each category being sampled obeys a random multinomial distribution, with a non-zero probability of sampling on only 4 categories, and the sampling ratio is 0.4: 0.4: 0.1: 0.1. Ultimately, the training set for each learnware contains 12,000 samples covering the data of 4 categories in CIFAR-10. +Second, we assess our algorithms on image datasets. It is worth noting that images of different sizes could be standardized through resizing, eliminating the need to consider heterogeneous feature cases. + +### Settings + +We choose the famous image classification dataset [CIFAR-10](https://www.cs.toronto.edu/~kriz/cifar.html), which consists of 60000 32x32 color images in 10 classes. A total of 50 learnwares are uploaded: each learnware contains a convolutional neural network trained on an unbalanced subset that includs 12000 samples from four categories with a sampling ratio of `0.4:0.4:0.1:0.1`. +A total of 100 user tasks are tested and each user task consists of 3000 samples of CIFAR-10 with six categories with a sampling ratio of `0.3:0.3:0.1:0.1:0.1:0.1`. -We constructed 50 target tasks using data from the test set of CIFAR-10. Similar to constructing the training set for the learnwares, to allow for some variation between tasks, we sampled the test set unevenly. Specifically, the probability of each category being sampled obeys a random multinomial distribution, with non-zero sampling probability on 6 categories, and the sampling ratio is 0.3: 0.3: 0.1: 0.1: 0.1: 0.1. Ultimately, each target task contains 3000 samples covering the data of 6 categories in CIFAR-10. +### Results -With this experimental setup, we evaluated the performance of RKME Image using 1 - Accuracy as the loss. +We assess the average performance of various methods using 1 - Accuracy as the loss metric. The following table and figure show that when users face a scarcity of labeled data or possess only a limited amount of it (less than 2000 instances), leveraging the learnware market can yield good performances.
@@ -347,34 +358,23 @@ With this experimental setup, we evaluated the performance of RKME Image using 1
-In some specific settings, the user will have a small number of labelled samples. In such settings, learning the weight of selected learnwares on a limited number of labelled samples can result in better performance than training directly on a limited number of labelled samples.
- +
## Text Scenario Experiment -### Datasets - -We conducted experiments on the widely used text benchmark dataset: [20-newsgroup](http://qwone.com/~jason/20Newsgroups/). 20-newsgroup is a renowned text classification benchmark with a hierarchical structure, featuring 5 superclasses {comp, rec, sci, talk, misc}. - -In the submitting stage, we enumerated all combinations of three superclasses from the five available, randomly sampling 50% of each combination from the training set to create datasets for 50 uploaders. - -In the deploying stage, we considered all combinations of two superclasses out of the five, selecting all data for each combination from the testing set as a test dataset for one user. This resulted in 10 users. The user's own training data was generated using the same sampling procedure as the user test data, despite originating from the training dataset. - -Model training comprised two parts: the first part involved training a tfidf feature extractor, and the second part used the extracted text feature vectors to train a naive Bayes classifier. +Finally, we evaluate our algorithms on text datasets. Text data naturally exhibit feature heterogeneity, but this issue can be addressed by applying a sentence embedding extractor. -Our experiments comprise two components: +### Settings -- **unlabeled_text_example** is designed to evaluate performance when users possess only testing data, searching and reusing learnware available in the market. -- **labeled_text_example** aims to assess performance when users have both testing and limited training data, searching and reusing learnware directly from the market instead of training a model from scratch. This helps determine the amount of training data saved for the user. +We conduct experiments on the well-known text classification dataset: [20-newsgroup](http://qwone.com/~jason/20Newsgroups/), which consists approximately 20000 newsgroup documents partitioned across 20 different newsgroups. +Similar to the image experiments, a total of 50 learnwares are uploaded. Each learnware is trained on a subset that includes only half of the samples from three superclasses and the model in it is a tf-idf feature extractor combined with a naive Bayes classifier. We define 10 user tasks, and each of them encompasses two superclasses. ### Results -- **unlabeled_text_example**: - -The table below presents the mean accuracy of search and reuse across all users: +The results are depicted in the following table and figure. Similarly, even when no labeled data is provided, the performance achieved through learnware identification and reuse can match that of the best learnware in the market. Additionally, utilizing the learnware market allows for a reduction of approximately 2000 samples compared to training models from scratch.
@@ -388,15 +388,11 @@ The table below presents the mean accuracy of search and reuse across all users:
-- **labeled_text_example**: - -We present the change curves in classification error rates for both the user's self-trained model and the multiple learnware reuse (EnsemblePrune), showcasing their performance on the user's test data as the user's training data increases. The average results across 10 users are depicted below:
- +
-From the figure above, it is evident that when the user's own training data is limited, the performance of multiple learnware reuse surpasses that of the user's own model. As the user's training data grows, it is expected that the user's model will eventually outperform the learnware reuse. This underscores the value of reusing learnware to significantly conserve training data and achieve superior performance when user training data is limited. # Citation @@ -418,12 +414,9 @@ Please acknowledge the use of our project by citing these papers in your work. T # About -## Contributors -We appreciate all contributions and thank all the contributors! +## How to Contribute -
- -
+Learnware is still young and may contain bugs and issues. We highly value and encourage contributions from the community. For detailed development guidelines, please consult our [Developer Guide](https://learnware.readthedocs.io/en/latest/about/dev.html). We kindly request that contributors adhere to the provided commit format and pre-commit configuration when participating in the project. Your valuable contributions are greatly appreciated. ## About Us diff --git a/README_zh.md b/README_zh.md new file mode 100644 index 0000000..85a5696 --- /dev/null +++ b/README_zh.md @@ -0,0 +1,433 @@ +
+ +
+
+
+ +

+ + Python Versions + + + Platform + + + PypI Versions + + + PyPI Downloads + + + Documentation Status + + + License + +

+ +

+

+ 中文 | + English +

+

+ +# 简介 + +学件范式由周志华教授在2016年提出 [1, 2],旨在构建一个巨大的模型平台系统:即学件基座系统,系统地组织管理世界各地的机器学习开发者分享的模型,并通过统一的方式识别、利用已有模型的能力快速解决新的机器学习任务。 + +本项目开发的 `learnware` 包对学件范式中的核心组件和算法进行了实现,全流程地支持学件上传、检测、组织、查搜、部署和复用等功能。基于良好的结构设计,`learnware` 包具有高度可扩展性,为后续相关算法和功能的开发打下坚实基础。 + +此外,`learnware` 包被用于「[北冥坞系统](https://bmwu.cloud)」中,作为系统的核心引擎支撑整个系统的运转。科研人员也可以使用 `learnware` 包高效地探索学件相关研究。 + +[1] Zhi-Hua Zhou. Learnware: on the future of machine learning. Frontiers of Computer Science, 2016, 10(4): 589–590
+[2] 周志华. 机器学习: 发展与未来. 中国计算机学会通讯, 2017, vol.13, no.1 (2016 中国计算机大会 keynote) + +## 学件范式 + +学件由性能优良的机器学习模型和描述模型的**规约**构成,即「学件 = 模型 + 规约」。 +学件的规约由「语义规约」和「统计规约」两部分组成: + +- 语义规约通过文本对模型的类型及功能进行描述; +- 统计规约则通过各类机器学习技术,刻画模型所蕴含的统计信息。 + +学件的规约刻画了模型的能力,使得模型能够在未来用户事先对学件一无所知的情况下被充分识别并复用,以满足用户需求。 + +
+ +
+ +如上图所示,在学件范式中,系统的工作流程主要分为以下两个阶段: + +- **提交阶段**:开发者自发地提交各式各样的学件到学件基座系统,而系统会对这些学件进行质量检查和进一步的组织。 +- **部署阶段**:当用户提交任务需求后,学件基座系统会根据学件规约推荐对用户任务有帮助的学件并指导用户进行部署和复用。 + +## 架构设计 + +
+ +
+ +架构设计的原则包括:解耦 (Decoupling)、自治 (Autonomy)、可重用性 (Reusability) 以及可扩展性 (Scalability)。 +上图从模块和工作流程的角度对整个架构进行了阐述。 + +- 针对工作流程 (Workflow),`learnware` 包括「提交阶段」和「部署阶段」。 + +
+ +| 阶段 | 描述 | +| ---- | ---- | +| 提交阶段 | 开发者自发地将学件提交到学件市场中,随后市场会进行学件检测并对这些学件进行相应地组织。 | +| 部署阶段 | 学件市场根据用户的任务需求推荐学件,并提供高效的学件部署和复用的方法。 | + +
+ +- 针对学件范式下各类模块 (Module),`learnware` 是一个包含 `Learnware`, `Market`, `Specification`, `Model`, `Reuse` 和 `Interface` 等模块的平台。 + +
+ +| 模块 | 描述 | +| ---- | ---- | +| `Learnware` | 学件由规约模块和模型模块组成。 | +| `Market` | 设计用于学件的组织、查搜和检测。 | +| `Specification` | 生成并存储学件的统计和语义规约,可用于学件的查搜和复用。 | +| `Model` | 包括模型和模型容器,可以提供统一的模型调用接口并自动创建隔离的模型运行环境。 | +| `Reuse` | 包括数据无关和数据相关的复用方式与异构学件对齐方式,可用于学件的部署和复用。 | +| `Interface` | 与北冥坞系统进行网络通讯的接口。| + +
+ + +# 快速上手 + +## 环境安装 + +`learnware` 包目前托管在 [PyPI](https://pypi.org/project/learnware/) 平台,其具体安装方式如下: + +```bash +pip install learnware +``` + +在 `learnware` 包中,除了基础类之外,许多核心功能(如学件规约生成、学件部署等)都需要依赖 `torch` 库。用户可选择手动安装 `torch`,或直接采用以下命令安装 `learnware` 包: + +```bash +pip install learnware[full] +``` + +但需要特别注意的是,由于用户本地环境可能较为复杂,安装 `learnware[full]` 并不能确保 `torch` 能够在用户的本地环境成功调用 `CUDA`。 + +## 学件准备 + +在 `learnware` 包中,每个学件都是一个 `zip` 包,其中至少需要包含以下四个文件: + +- `learnware.yaml`:学件配置文件; +- `__init__.py`:提供使用模型的方法; +- `stat.json`:学件的统计规约,其文件名可自定义并记录在 learnware.yaml 中; +- `environment.yaml` 或 `requirements.txt`:指明模型的运行环境。 + +为方便大家构建学件,我们提供了「[学件模板](https://www.bmwu.cloud/static/learnware-template.zip)」,大家可在其基础上构建自己的学件。 +关于学件 `zip` 包中各文件的详细描述可参考文档:[学件准备](https://learnware.readthedocs.io/en/latest/workflows/upload.html#prepare-learnware)。 + +## 工作流程 + +用户可根据以下步骤实现 `learnware` 中的工作流程。 + +### 初始化学件市场 + +`EasyMarket` 类提供了学件市场的核心功能。根据如下代码,可以实例化一个名为 "demo" 的基础学件市场: + +```python +from learnware.market import instantiate_learnware_market + +# 实例化学件市场 +demo_market = instantiate_learnware_market(market_id="demo", name="easy", rebuild=True) +``` + +### 上传学件 + +在将学件上传到「学件市场」之前,需要创建相应的语义规约,即 `semantic_spec`。这涉及选择或输入预定义的语义标签的值,以描述你的任务和模型的特性。 + +例如,以下代码示例生成了适用于教育场景的 `Scikit-Learn` 类型模型的语义规约。该模型用于对表格数据执行分类任务: + +```python +from learnware.specification import generate_semantic_spec + +semantic_spec = generate_semantic_spec( + name="demo_learnware", + data_type="Table", + task_type="Classification", + library_type="Scikit-learn", + scenarios="Education", + license="MIT", +) +``` + +得到语义规约后,可以使用如下代码上传学件: + +```python +demo_market.add_learnware(zip_path, semantic_spec) +``` + +其中 `zip_path` 为待上传学件 `zip` 包的路径。 + +### 语义规约查搜 + +为了找到与你的任务目标相符的学件,你需要提供一个名为 `user_semantic` 的语义规约,来概述你的任务特点。随后,学件市场将通过 `user_semantic` 进行语义查搜,识别与你的任务需求相近的学件。 + +```python +# 构造包含语义规约的 user_info +user_info = BaseUserInfo(id="user", semantic_spec=semantic_spec) + +# search_learnware: 当 user_info 不包含统计规约时,仅执行语义规约查搜 +search_result = easy_market.search_learnware(user_info) +single_result = search_results.get_single_results() + +# single_result: 语义规约查搜返回的 Tuple[Score, Learnware] 列表 +print(single_result) +``` + +### 统计规约查搜 + +如果提供统计规约文件 `stat.json`,学件市场可以基于上述查搜结果进一步进行更准确的查搜。 +此阶段的查搜将利用统计信息来识别一个或多个对你的任务有帮助的学件。 + +以下代码展示了使用 Reduced Kernel Mean Embedding (RKME) 作为统计规约进行查搜的例子: + +```python +import learnware.specification as specification + +user_spec = specification.RKMETableSpecification() + +# unzip_path: 解压缩的学件文件夹路径 +user_spec.load(os.path.join(unzip_path, "rkme.json")) +user_info = BaseUserInfo( + semantic_spec=user_semantic, stat_info={"RKMETableSpecification": user_spec} +) +search_result = easy_market.search_learnware(user_info) + +single_result = search_results.get_single_results() +multiple_result = search_results.get_multiple_results() + +# search_item.score: 根据 MMD 距离,按降序排列 +# search_item.learnware.id: 学件 id, 根据查搜匹配度按降序排列 +for search_item in single_result: + print(f"score: {search_item.score}, learnware_id: {search_item.learnware.id}") + +# mixture_item.learnwares: 可结合使用的学件集合 +# mixture_item.score: `mixture_item.learnwares` 中各学件集合的查搜匹配度 +for mixture_item in multiple_result: + print(f"mixture_score: {mixture_item.score}\n") + mixture_id = " ".join([learnware.id for learnware in mixture_item.learnwares]) + print(f"mixture_learnware: {mixture_id}\n") +``` + +### 多学件复用 + +使用上一步中返回的学件列表 `mixture_learnware_list`,你可以轻松地复用它们对自己的数据进行预测,而无需从头开始训练模型。我们提供了两种方法来重用学件集合:`JobSelectorReuser` 和 `AveragingReuser`。将以下代码片段中的 `test_x` 替换为你的测试数据,即可实现学件复用: + +```python +from learnware.reuse import JobSelectorReuser, AveragingReuser + +# 使用 jobselector reuser 复用查搜到的学件, 并对 text_x 进行预测 +reuse_job_selector = JobSelectorReuser(learnware_list=mixture_item.learnwares) +job_selector_predict_y = reuse_job_selector.predict(user_data=test_x) + +# 使用 averaging ensemble reuser 复用查搜到的学件, 并对 text_x 进行预测 +reuse_ensemble = AveragingReuser(learnware_list=mixture_item.learnwares) +ensemble_predict_y = reuse_ensemble.predict(user_data=test_x) +``` + +我们还提供了两种方法,可基于用户的有标记数据来复用给定的学件集合:`EnsemblePruningReuser` 和 `FeatureAugmentReuser`。 +参考下述代码,其中 `test_x` 为测试数据,`train_x, train_y` 为有标记的训练数据: + +```python +from learnware.reuse import EnsemblePruningReuser, FeatureAugmentReuser + +# 使用 ensemble pruning reuser 复用查搜到的学件, 并对 text_x 进行预测 +reuse_ensemble = EnsemblePruningReuser(learnware_list=mixture_item.learnwares, mode="classification") +reuse_ensemble.fit(train_x, train_y) +ensemble_pruning_predict_y = reuse_ensemble.predict(user_data=test_x) + +# 使用 feature augment reuser 复用查搜到的学件, 并对 text_x 进行预测 +reuse_feature_augment = FeatureAugmentReuser(learnware_list=mixture_item.learnwares, mode="classification") +reuse_feature_augment.fit(train_x, train_y) +feature_augment_predict_y = reuse_feature_augment.predict(user_data=test_x) +``` + +### 自动工作流程示例 + +`learnware` 包提供了自动化的工作流程示例,包括准备学件、在学件市场中上传和删除学件,以及使用语义和统计规约查搜学件。 +工作流程示例可参考 `test/test_workflow/test_workflow.py` 文件。 + +# 实验示例 + +我们构建了各种类型的实验场景,并进行了充分的测试,以评估规约生成、学件查搜以及在表格、图像和文本数据上学件复用的基线算法。 + +## 实验配置 + +所有实验均在一台 Linux 服务器上完成,其具体规格如下表所示。服务器的所有处理器均用于训练和评估。 + +
+ +| 系统 | GPU | CPU | +|----------------------|--------------------|--------------------------| +| Ubuntu 20.04.4 LTS | Nvidia Tesla V100S | Intel(R) Xeon(R) Gold 6240R | + +
+ +## 表格场景实验 + +在各种表格数据集上,我们首先评估了从学件市场中识别和复用与用户任务具有相同特征空间的学件的性能。另外,由于表格任务通常来自异构的特征空间,我们还评估了从不同特征空间中识别和复用学件的性能。 + +### 实验设置 + +我们的实验利用了销量预测领域的三个公共数据集:[Predict Future Sales (PFS)](https://www.kaggle.com/c/competitive-data-science-predict-future-sales/data),[M5 Forecasting (M5)](https://www.kaggle.com/competitions/m5-forecasting-accuracy/data) 和 [Corporacion](https://www.kaggle.com/competitions/favorita-grocery-sales-forecasting/data)。为了扩大实验规模,我们对这些数据集应用了多种特征工程方法。然后,我们将每个数据集按店铺划分,并进一步将每个店铺的数据划分为训练集和测试集。我们在每个 Corporacion 和 PFS 训练集上训练了一个 LightGBM 模型,而测试集和 M5 数据集被用于构建用户任务。基于上述方式,我们构建了一个包含 265 个学件的学件市场,涵盖了五种特征空间和两种标签空间。所有这些学件都已上传至[北冥坞学件基座系统](https://bmwu.cloud/)。 + +### 基线算法 + +复用学件的最基本方式是 Top-1 复用 (Top-1 reuser),即直接使用由 RKME 规约选择的单个学件。此外,我们实现了两种数据无关复用器和两种数据相关复用器,它们可用于复用从市场中识别出的单个或多个有用的学件。当用户无标记的数据时,JobSelector 复用器通过训练一个任务选择器为不同的样本选择不同的学件;AverageEnsemble 复用器使用集成方法进行预测。在用户有测试数据和少量有标记训练数据的情况下,EnsemblePruning 复用器有选择地集成一组学件,选择最适合用户任务的学件;FeatureAugment 复用器将每个接收到的学件视为特征增强器,将其输出视为新特征,然后在增强的特征集上构建一个简单的模型。JobSelector 和 FeatureAugment 只对表格数据有效,而其他方法也适用于文本和图像数据。 + +### 同构场景 + +在同构场景中,PFS 数据集中的 53 家商店被视为 53 个独立的用户。每个商店使用自己的测试数据作为用户数据,并应用与学件市场相同的特征工程方法。这些用户随后可以在市场内搜索与其任务具有相同特征空间的同构学件。 + +当用户没有标记的数据或只有少量有标记数据时,我们对不同的基线算法进行了比较。下表显示了所有用户的平均损失。结果表明,我们提供的方法远远优于从市场中随机选择一个学件的结果。 + +
+ +| Setting | MSE | +|-----------------------------------|--------| +| Mean in Market (Single) | 0.897 | +| Best in Market (Single) | 0.756 | +| Top-1 Reuse (Single) | 0.830 | +| Job Selector Reuse (Multiple) | 0.848 | +| Average Ensemble Reuse (Multiple) | 0.816 | + +
+ +下图展示了当用户提供不同数量有标记数据的结果;对于每个用户,我们进行了多次实验,并计算了损失的均值和标准差;图中展示了所有用户的平均损失。其表明,当用户只有有限的训练数据时,识别和复用单个或多个学件相对于用户自己训练的模型表现出更好的性能。 + +
+ +
+ +### 异构场景 + +基于学件市场中学件与用户任务之间的相似性,异构情况可以进一步分为不同的特征工程和不同的任务场景。 + +#### 不同特征工程的场景 + +我们将 PFS 数据集中的 41 家商店视为用户,采用与市场中学件不同的特征工程方法生成他们的用户数据。因此,尽管市场上的某些学件也是为 PFS 数据集设计的,但特征空间并不完全一致。 + +在这个实验设置中,我们研究了各种数据无关复用器。下表中的结果表明,即使用户缺乏标记数据,市场也能表现出较强的性能,特别是使用多学件复用方法 AverageEnsemble 时。 + +
+ +| Setting | MSE | +|-----------------------------------|--------| +| Mean in Market (Single) | 1.149 | +| Best in Market (Single) | 1.038 | +| Top-1 Reuse (Single) | 1.105 | +| Average Ensemble Reuse (Multiple) | 1.081 | + +
+ + +#### 不同的任务场景 + +我们在 M5 数据集的所有十家商店上采用了三种不同的特征工程方法,总共生成了 30 个用户。尽管销量预测的总体任务与市场上的学件所处理的任务相符,但没有一个学件是为 M5 销量预测任务专门设计的。 + +在下图中,我们展示了用户自行训练的模型和几种学件复用方法的损失曲线。显然,异构学件在用户标记数据有限的情况下表现出了对用户任务的有效性。 + +
+ +
+ + +## 图像场景实验 + +其次,我们在图像数据集上评估了我们的算法。值得注意的是,不同尺寸的图像可以通过调整大小进行标准化,无需考虑异构特征情况。 + +### 实验设置 + +我们选择了经典的图像分类数据集 [CIFAR-10](https://www.cs.toronto.edu/~kriz/cifar.html),其中包含 10 个类别的 60000 张 32x32 的彩色图像。总共上传了 50 个学件:每个学件包含一个卷积神经网络,该网络在一个不平衡的子集上进行训练,包括来自四个类别的 12000 个样本,采样比例为 `0.4:0.4:0.1:0.1`。 +总共测试了 100 个用户任务,每个用户任务包含 3000 个 CIFAR-10 样本,分为六个类别,采样比例为 `0.3:0.3:0.1:0.1:0.1:0.1`。 + +### 实验结果 + +我们使用 `1 - Accuracy` 作为损失度量来评估各种方法的平均性能。下述实验结果显示,当用户面临标记数据的稀缺或仅拥有有限数量的标记数据(少于 2000 个实例)时,利用学件市场可以获得更好的性能。 + +
+ +| Setting | Accuracy | +|-----------------------------------|----------| +| Mean in Market (Single) | 0.655 | +| Best in Market (Single) | 0.304 | +| Top-1 Reuse (Single) | 0.406 | +| Job Selector Reuse (Multiple) | 0.406 | +| Average Ensemble Reuse (Multiple) | 0.310 | + +
+ +
+ +
+ +## 文本场景实验 + +最后,我们在文本数据集上对我们的算法进行了评估。文本数据的特征天然异构,但这个问题可以通过使用句子嵌入提取器 (Sentence Embedding Extractor) 来解决。 + +### 实验设置 + +我们在经典的文本分类数据集上进行了实验:[20-newsgroup](http://qwone.com/~jason/20Newsgroups/),该数据集包含大约 20000 份新闻文档,包含 20 个不同的新闻组。 +与图像实验类似,我们一共上传了 50 个学件。每个学件都是在一个子集上进行训练,该子集仅包括三个超类中一半样本的数据,其中的模型为 `tf-idf` 特征提取器与朴素贝叶斯分类器的结合。我们定义了 10 个用户任务,每个任务包括两个超类。 + +### 实验结果 + +结果如下表和图所示。同样地,即使没有提供标记数据,通过学件的识别和复用所达到的性能可以与市场上最佳学件相匹敌。此外,利用学件市场相对于从头训练模型可以减少约 2000 个样本。 + +
+ +| Setting | Accuracy | +|-----------------------------------|----------| +| Mean in Market (Single) | 0.507 | +| Best in Market (Single) | 0.859 | +| Top-1 Reuse (Single) | 0.846 | +| Job Selector Reuse (Multiple) | 0.845 | +| Average Ensemble Reuse (Multiple) | 0.862 | + +
+ + +
+ +
+ + +# 引用 + +如果你在研究或工作中使用了我们的项目,请引用下述论文,感谢你的支持! + +```bibtex +@article{zhou2022learnware, + author = {Zhou, Zhi-Hua and Tan, Zhi-Hao}, + title = {Learnware: Small Models Do Big}, + journal = {SCIENCE CHINA Information Sciences}, + year = {2024}, + volume = {67}, + number = {1}, + pages = {1--12}, +} +``` + +# 关于 + +## 如何贡献 + +`learnware` 还很年轻,可能存在错误和问题。我们非常欢迎大家为 `learnware` 做出贡献。 +我们为所有的开发者提供了详细的[项目开发指南](https://learnware.readthedocs.io/en/latest/about/dev.html),并设置了相应的 commit 格式和 pre-commit 配置,请大家遵守。 +非常感谢大家的贡献! + +## 关于我们 + +`learnware` 由 LAMDA 北冥坞研发团队开发和维护,更多信息可参考:[团队简介](https://docs.bmwu.cloud/zh-CN/about-us.html)。 \ No newline at end of file diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..faa5ff0 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,30 @@ +# Security Policy + +Welcome to our project! We are committed to maintaining the security of our project and take security issues very seriously. Our team promptly addresses any reported security vulnerabilities to ensure the safety and integrity of our project. + +## Reporting Security Issues + +Should you discover a security vulnerability or encounter any security-related issue in our project, we encourage you to report it to us immediately with the following methods: + +- Email: [bmwu-support@lamda.nju.edu.cn](mailto:bmwu-support@lamda.nju.edu.cn) + +When reporting an issue, kindly include as much detail as possible: + +- **Description of the Issue**: Clearly describe what you have encountered. +- **Scope of the Impact**: Assess how the issue affects the project or its users. +- **Steps to Reproduce**: Provide a step-by-step guide to replicate the issue. +- **Supporting Material**: Attach any relevant screenshots, example code, or other materials that could aid in understanding the issue. + +## Security Issue Handling Process + +Upon receiving a report of a security issue, we will: + +1. Promptly validate the reported issue to confirm its validity. +2. Once confirmed, our team will diligently work towards resolving the issue as swiftly as possible. +3. After resolving the issue, we will release a security advisory in accordance with our update schedule. + +## Acknowledgement of Contributions + +We deeply value the community's efforts in helping us maintain the security of our project. Therefore, we are committed to acknowledging the contributions of those who report security issues responsibly. We will recognize contributors in our advisories and public communications related to the security issue they helped address, respecting their privacy and confidentiality preferences. + +Thank you for your support in keeping our project secure. Your vigilance, responsible reporting, and contributions are greatly appreciated and play a vital role in our continuous effort to improve security. diff --git a/docs/_static/img/Hetero_labeled_curves.svg b/docs/_static/img/Hetero_labeled_curves.svg new file mode 100644 index 0000000..b0133ab --- /dev/null +++ b/docs/_static/img/Hetero_labeled_curves.svg @@ -0,0 +1,1726 @@ + + + + + + + + 2024-01-14T12:29:08.080846 + image/svg+xml + + + Matplotlib v3.8.1, https://matplotlib.org/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/_static/img/Homo_labeled_curves.svg b/docs/_static/img/Homo_labeled_curves.svg new file mode 100644 index 0000000..4c0d4c3 --- /dev/null +++ b/docs/_static/img/Homo_labeled_curves.svg @@ -0,0 +1,1737 @@ + + + + + + + + 2024-01-14T11:58:56.252636 + image/svg+xml + + + Matplotlib v3.8.1, https://matplotlib.org/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/_static/img/image_labeled.svg b/docs/_static/img/image_labeled_curves.svg similarity index 64% rename from docs/_static/img/image_labeled.svg rename to docs/_static/img/image_labeled_curves.svg index 0de61b1..1c8373e 100644 --- a/docs/_static/img/image_labeled.svg +++ b/docs/_static/img/image_labeled_curves.svg @@ -1,16 +1,16 @@ - + - 2023-12-27T16:40:12.240585 + 2024-01-14T11:41:39.775455 image/svg+xml - Matplotlib v3.8.0, https://matplotlib.org/ + Matplotlib v3.8.1, https://matplotlib.org/ @@ -21,83 +21,88 @@ - - - - - + + - - - + + + + + - - + - + - + + + + - + - + - + + + + - + - + - + + + + - + - + @@ -241,14 +261,19 @@ z - + + + + - + - + @@ -257,14 +282,19 @@ z - + + + + - + - + - - + + + - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - + + + + - - + - + - + + + + - + - + @@ -751,14 +811,19 @@ z - + + + + - + - + - + + + + - + - + @@ -797,14 +867,19 @@ z - + + + + - + - + @@ -814,14 +889,19 @@ z - + + + + - + - + @@ -831,14 +911,19 @@ z - + + + + - + - + @@ -848,14 +933,19 @@ z - + + + + - + - + @@ -865,9 +955,22 @@ z - - + + + - - - - - - - - - - - - - + + + + + + + + + + + + + + - - + + - - - - - - - - + + + + + + + - - + + - - - - - - - - + + + + + + + - - - - - + - - - - + - + - + - - + - + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + diff --git a/docs/_static/img/learnware_framework.svg b/docs/_static/img/learnware_framework.svg index 92e0d37..bf4326b 100644 --- a/docs/_static/img/learnware_framework.svg +++ b/docs/_static/img/learnware_framework.svg @@ -1,4 +1,4 @@ -
Market
Market
Specification
Specification
Interface
Interface
Workflow
Workflow
Learnware Standard
Learnware Standard
Zip Package





Zip Package...
Semantic
Specification

Semantic...
Yaml Config
Yaml Config
Model File
Model File
Env Dependencies
Env Dependencies
Learnware
Learnware
Model



Model...
Classfication
Classficat...
Feature Extraction
Feature Extract...
Regression
Regression
Specification



Specification...
Semantic
Semantic
Others
Others
Statistical
Statistical
create
cre...
Market
Market
Checker







Checker...
Searcher



Searcher...
Semantic
Semantic
Statistical
Statisti...
Conda
Conda
Semantic
Semantic
Statictical
Statictica...
Database
Database
Organizer


Organizer...
Easy
Easy
Hetero
Hetero
submit
sub...
Submitting Workflow
Submitting Workflow
Deploying Workflow
Deploying Workflow
UserInfo






UserInfo...
Semantic
Spec
Semantic...
Statistical
Info
Statisti...
SearchResult






SearchResult...
Scores
Scores
Learnwares



Learnwares...
search
sea...
return
ret...
Executable
Learnwares





Executable...
ModelContainer


ModelContaine...
Docker
Docker
Conda
Conda
Reuser
Reuser
Model
Model
Specification
Specificat...
ContainerManager
ContainerManager

Executable
Learnwares

Executable...
Data Free Reuser


Data Free Reuser...
Averaging
Averaging
JobSelector
JobSelecto...
Data-Dependent Reuser



Data-Dependent Reuser...
Ensemble
Purning
Ensemble...
Feature
Argument
Feature...
Aligner







Aligner...
Feature
Aligner
Featur...
Label
Aligner
Label...
Specification
Specificati...
Learnware Client





Learnware Client...
login
login
BeimingWu Server



BeimingWu Server...
search
search
upload
upload
delete
delete
update
update
load
load
Network
Network
Statistical Specification
Statistical Specification
Semantic Specification










Semantic Specificati...
Data
Data
Feature
Featur...
Task
Task
Label
Label
Library
Librar...
Description
Descripti...
Name
Name
Scenario
Scenario
License
Licens...
Others
Others
System Specification
System Specification
Regular Specification
Regular Specification
RKMEStatSpecification










RKMEStatSpecification...
Data Set


Data Set...
Table
Table
Image
Image
Text
Text
RKME
RKME
Reduced Set


Reduced Set...
Weights
Weight...
Reduced Points
Reduced Point...
HeteroMapSpecification









HeteroMapSpecification...
RKME Reduced Set
RKME Reduced Set
HeteroMapping
HeteroMapping
Hetero Reduced Set



Hetero Reduced Set...
Weights
Weight...
Homo Embeddings
Homo Embeddings
Organizer
Organizer
Searcher
Searcher
EasyOrganizer
EasyOrganizer
HeteroOrganizer
HeteroOrganizer
Database



Database...
SqlLite
SqlLite
PostgresSql
PostgresSq...
HeteroMapping
HeteroMapping
HeteroMap
Specification
HeteroMap...
update
upd...
generate
gen...
save
save
load
load
save
save
load
load
Homo
StatSearcher
Homo...
Semantic Searcher



Semantic Searcher...
Checker











Checker...
Conda Checker








Conda Checker...
Semantic Checker
Semantic Checke...
Executable
Learnwares



Executable...
ModelContainer
ModelContaine...
Statistical Checker
Statistical Che...
check
che...
HeteroMap
Specification
HeteroMap...
RKMEStat
Specification
RKMEStat...
Heterom
StatSearcher
Heterom...
Fuzzy
Semantic Searcher
Fuzzy...
Exact
Semantic Searcher
Exact...
match
mat...
match
mat...
Text is not SVG - cannot display
\ No newline at end of file +
Market
Market
Specification
Specification
Interface
Interface
Workflow
Workflow
Learnware Standard
Learnware Standard
Zip Package





Zip Package...
Semantic
Specification

Semantic...
Yaml Config
Yaml Config
Model File
Model File
Env Dependencies
Env Dependencies
Learnware
Learnware
Model



Model...
Classfication
Classficat...
Feature Extraction
Feature Extract...
Regression
Regression
Specification



Specification...
Semantic
Semantic
Others
Others
Statistical
Statistical
create
cre...
Market
Market
Checker







Checker...
Searcher



Searcher...
Semantic
Semantic
Statistical
Statisti...
Conda
Conda
Semantic
Semantic
Statictical
Statictica...
Database
Database
Organizer


Organizer...
Easy
Easy
Hetero
Hetero
submit
sub...
Submitting Workflow
Submitting Workflow
Deploying Workflow
Deploying Workflow
UserInfo






UserInfo...
Semantic
Spec
Semantic...
Statistical
Info
Statisti...
SearchResult






SearchResult...
Scores
Scores
Learnwares



Learnwares...
search
sea...
return
ret...
Executable
Learnwares





Executable...
ModelContainer


ModelContaine...
Docker
Docker
Conda
Conda
Reuser
Reuser
Model
Model
Specification
Specificat...
ContainerManager
ContainerManager

Executable
Learnwares

Executable...
Data Free Reuser


Data Free Reuser...
Averaging
Averaging
JobSelector
JobSelecto...
Data-Dependent Reuser



Data-Dependent Reuser...
Ensemble
Purning
Ensemble...
Feature
Argument
Feature...
Aligner







Aligner...
Feature
Aligner
Featur...
Label
Aligner
Label...
Specification
Specificati...
Learnware Client





Learnware Client...
login
login
BeimingWu Server



BeimingWu Server...
search
search
upload
upload
delete
delete
update
update
load
load
Network
Network
Statistical Specification
Statistical Specification
Semantic Specification










Semantic Specificati...
Data
Data
Feature
Feature
Task
Task
Label
Label
Library
Library
Description
Descripti...
Name
Name
Scenario
Scenario
License
License
Others
Others
System Specification
System Specification
Regular Specification
Regular Specification
RKMEStatSpecification










RKMEStatSpecification...
Data Set


Data Set...
Table
Table
Image
Image
Text
Text
RKME
RKME
Reduced Set


Reduced Set...
Weights
Weights
Reduced Points
Reduced Point...
HeteroMapSpecification









HeteroMapSpecification...
RKME Reduced Set
RKME Reduced Set
HeteroMapping
HeteroMapping
Hetero Reduced Set



Hetero Reduced Set...
Weights
Weights
Homo Embeddings
Homo Embeddings
Organizer
Organizer
Searcher
Searcher
EasyOrganizer
EasyOrganizer
HeteroOrganizer
HeteroOrganizer
Database



Database...
SqlLite
SqlLite
PostgresSql
PostgresSq...
HeteroMapping
HeteroMapping
HeteroMap
Specification
HeteroMap...
update
upd...
generate
gen...
save
save
load
load
save
save
load
load
Homo
StatSearcher
Homo...
Semantic Searcher



Semantic Searcher...
Checker











Checker...
Conda Checker








Conda Checker...
Semantic Checker
Semantic Checke...
Executable
Learnwares



Executable...
ModelContainer
ModelContaine...
Statistical Checker
Statistical Che...
check
che...
HeteroMap
Specification
HeteroMap...
RKMEStat
Specification
RKMEStat...
Heterom
StatSearcher
Heterom...
Fuzzy
Semantic Searcher
Fuzzy...
Exact
Semantic Searcher
Exact...
match
mat...
match
mat...
Text is not SVG - cannot display
\ No newline at end of file diff --git a/docs/_static/img/learnware_market-zh.svg b/docs/_static/img/learnware_market-zh.svg new file mode 100644 index 0000000..23a91f4 --- /dev/null +++ b/docs/_static/img/learnware_market-zh.svg @@ -0,0 +1 @@ +任务C任务1任务2“ab”Spam?0011模型1模型2spamemailemailab>0.8ab0.8spamemailour>1.2our1.2模型Cspecificationspecification学件C学件2学件1specification北冥坞:学件基座系统开发者分享模型至系统用户通过系统解决任务开发者标准化的学件格式任务需求推荐查搜提交直接使用模型用少量数据微调模型(可选) \ No newline at end of file diff --git a/docs/_static/img/logo/logo.svg b/docs/_static/img/logo/logo.svg new file mode 100644 index 0000000..a492ec9 --- /dev/null +++ b/docs/_static/img/logo/logo.svg @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/docs/_static/img/logo/logo1.png b/docs/_static/img/logo/logo1.png deleted file mode 100644 index f466430..0000000 Binary files a/docs/_static/img/logo/logo1.png and /dev/null differ diff --git a/docs/_static/img/table_hetero_labeled.png b/docs/_static/img/table_hetero_labeled.png deleted file mode 100644 index b8aedaf..0000000 Binary files a/docs/_static/img/table_hetero_labeled.png and /dev/null differ diff --git a/docs/_static/img/text_labeled.svg b/docs/_static/img/text_labeled_curves.svg similarity index 63% rename from docs/_static/img/text_labeled.svg rename to docs/_static/img/text_labeled_curves.svg index 669247e..bb316f7 100644 --- a/docs/_static/img/text_labeled.svg +++ b/docs/_static/img/text_labeled_curves.svg @@ -1,16 +1,16 @@ - + - 2023-12-27T16:34:04.155470 + 2024-01-14T11:39:19.140081 image/svg+xml - Matplotlib v3.8.0, https://matplotlib.org/ + Matplotlib v3.8.1, https://matplotlib.org/ @@ -21,83 +21,88 @@ - - - - - + + - - - + + + + + - - + - + - + + + + - + - + - + + + + - + - + - + + + + - + - + @@ -241,14 +261,19 @@ z - + + + + - + - + @@ -257,14 +282,19 @@ z - + + + + - + - + - - + + + - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - + + + + - - + - + - + + + + - + - + @@ -717,14 +777,19 @@ z - + + + + - + - + @@ -733,14 +798,19 @@ z - + + + + - + - + - + + + + - + - + @@ -799,14 +874,19 @@ z - + + + + - + - + @@ -815,14 +895,19 @@ z - + + + + - + - + @@ -831,9 +916,22 @@ z - - + + + - - - - - - - - - - - - - + + + + + + + + + + + + + + - - + + - - - - - - - - + + + + + + + - - + + - - - - - - - - + + + + + + + - - - - - + - - - - + - + - + - - + - + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + diff --git a/docs/about/about.rst b/docs/about/about.rst index 5777ca5..8d9bb8f 100644 --- a/docs/about/about.rst +++ b/docs/about/about.rst @@ -2,10 +2,17 @@ About Us ================ -We thank all the contributors for the development of learnware package: +The R&D Team of ``learnware`` is from `Nanjing University's LAMDA Research Institute `_, with Prof. `Zhi-Hua Zhou `_ serving as the Founding Director. -.. image:: https://github.com/Learnware-LAMDA/Learnware/graphs/contributors - :align: center +LAMDA is affiliated with the National Key Laboratory for Novel Software Technology, the Department of Computer Science & Technology and the School of Artificial Intelligence, Nanjing University, China. It locates at Computer Science and Technology Building in the Xianlin campus of Nanjing University, mainly in Rm910. -In LAMDA Group, also many people participate the discussions, learnware package design and development and so on. -For more details about us, please refer to `LAMDA Group `_. \ No newline at end of file +"LAMDA" means "Learning And Mining from DatA". The main research interests of LAMDA include machine learning, data mining, pattern recognition, information retrieval, evolutionary computation, neural computation, and some other related areas. Currently our research mainly involves: ensemble learning, semi-supervised and active learning, multi-instance and multi-label learning, cost-sensitive and class-imbalance learning, metric learning, dimensionality reduction and feature selection, structure learning and clustering, theoretical foundations of evolutionary computation, improving comprehensibility, content-based image retrieval, web search and mining, face recognition, computer-aided medical diagnosis, bioinformatics, etc. + +The ``learnware`` package is currently maintained by the LAMDA Beimingwu R&D Team, consisting of: Zhi-Hua Zhou, Yang Yu, Zhi-Hao Tan, Jian-Dong Liu, Peng Tan, Xiao-Dong Bi, Qin-Cheng Zheng, Xiao-Chuan Zou, Yi Xie, Hai-Tian Liu, Hao-Yu Shi, Xin-Yu Zhang and others. + +Contact +========== + +``learnware`` is still young. It may contain bugs and issues. Contributions are welcome. If you encounter any problems or have any suggestions while using the ``learnware`` package, please contact us: + +- Email: bmwu-support@lamda.nju.edu.cn \ No newline at end of file diff --git a/docs/about/dev.rst b/docs/about/dev.rst index 79714f7..3ffbe77 100644 --- a/docs/about/dev.rst +++ b/docs/about/dev.rst @@ -6,7 +6,7 @@ For Developer Install with Dev Mode ======================= -As a developer, you often want make changes to ``Learnware Market`` and hope it would reflect directly in your environment without reinstalling it. You can install ``Learnware Market`` in editable mode with following command. +As a developer, you often want make changes to ``learnware`` and hope it would reflect directly in your environment without reinstalling it. You can install ``learnware`` in editable mode with following command. .. code-block:: bash @@ -33,7 +33,7 @@ The suffix specifies the specific nature of the modification, with the initial l Examples: The following are all valid: - [DOC] Fix the document -- [FIX, ENH] Fix the bug and add some feature" +- [FIX, ENH] Fix the bug and add some features Docstring @@ -47,7 +47,7 @@ Continuous Integration ====================== Continuous Integration (CI) tools help you stick to the quality standards by running tests every time you push a new commit and reporting the results to a pull request. -``Learnware Market`` will check the following tests when you pull a request: +This project will check the following tests when you pull a request: 1. We will check your code length, you can fix your code style by the following commands: .. code-block:: bash diff --git a/docs/references/api.rst b/docs/references/api.rst index ed23e48..e70810b 100644 --- a/docs/references/api.rst +++ b/docs/references/api.rst @@ -3,7 +3,7 @@ API Reference ================================ -Here you can find high-level ``Learnware`` interfaces. +Here you can find high-level interfaces in the ``learnware`` package. Market ==================== @@ -22,7 +22,7 @@ Organizer .. autoclass:: learnware.market.EasyOrganizer :members: -.. autoclass:: learnware.market.HeteroOrganizer +.. autoclass:: learnware.market.HeteroMapTableOrganizer :members: Searcher @@ -33,13 +33,13 @@ Searcher .. autoclass:: learnware.market.EasySearcher :members: -.. autoclass:: learnware.market.EasyExactSemanticSearcher +.. autoclass:: learnware.market.easy.EasyExactSemanticSearcher :members: -.. autoclass:: learnware.market.EasyFuzzSemanticSearcher +.. autoclass:: learnware.market.easy.EasyFuzzSemanticSearcher :members: -.. autoclass:: learnware.market.EasyStatSearcher +.. autoclass:: learnware.market.easy.EasyStatSearcher :members: .. autoclass:: learnware.market.HeteroSearcher @@ -51,9 +51,6 @@ Checker .. autoclass:: learnware.market.BaseChecker :members: -.. autoclass:: learnware.market.EasyChecker - :members: - .. autoclass:: learnware.market.EasySemanticChecker :members: @@ -145,14 +142,14 @@ Base Model Container ------------- -.. autoclass:: learnware.client.ModelContainer +.. autoclass:: learnware.client.container.ModelContainer :members: -.. autoclass:: learnware.client.ModelCondaContainer +.. autoclass:: learnware.client.container.ModelCondaContainer :members: -.. autoclass:: learnware.client.ModelDockerContainer +.. autoclass:: learnware.client.container.ModelDockerContainer :members: -.. autoclass:: learnware.client.LearnwaresContainer +.. autoclass:: learnware.client.container.LearnwaresContainer :members: \ No newline at end of file diff --git a/docs/references/beimingwu.rst b/docs/references/beimingwu.rst index c616289..d1840cd 100644 --- a/docs/references/beimingwu.rst +++ b/docs/references/beimingwu.rst @@ -24,7 +24,7 @@ In addition, the Beimingwu system also has the following features: - ``Diverse Learnware Search``: The Beimingwu system supports both semantic specifications and statistical specifications searches, covering data types such as tables, images, and text. In addition, for table-based tasks, the system also supports the search for heterogeneous table learnwares. - ``Local Learnware Deployment``: The Beimingwu system provides interfaces for learnware deployment and learnware reuse in the learnware package, facilitating users' convenient and secure learnware deployment. - ``Data Privacy Protection``: The Beimingwu system operations, including learnware upload, search, and deployment, do not require users to upload local data. All relevant statistical specifications are generated locally by users, ensuring data privacy. -- ``Fully Open Source``: The Beimingwu system's source code is completely open-source, including the learnware package and frontend/backend code. The learnware package is highly extensible, making it easy to integrate new specification designs, learnware system designs, and learnware reuse methods in the future. +- ``Open Source System``: The Beimingwu system's source code is open-source, including the learnware package and frontend/backend code. The learnware package is highly extensible, making it easy to integrate new specification designs, learnware system designs, and learnware reuse methods in the future. Beimingwu is the first system-level implementation of the learnware paradigm. This pioneering venture is just the beginning, with vast opportunities for enhancement and growth in the related technological fields still ahead. \ No newline at end of file diff --git a/docs/start/exp.rst b/docs/start/exp.rst index b072fd1..8faad5a 100644 --- a/docs/start/exp.rst +++ b/docs/start/exp.rst @@ -1,4 +1,5 @@ .. _exp: + ================================ Experiments and Examples ================================ @@ -19,122 +20,98 @@ Ubuntu 20.04.4 LTS Nvidia Tesla V100S Intel(R) Xeon(R) Gold 6240R Tabular Data Experiments =========================== -Datasets ------------------- -Our study involved three public datasets in the sales forecasting field: `Predict Future Sales (PFS) `_, -`M5 Forecasting (M5) `_ and `Corporacion `_. -We applied various pre-processing methods to these datasets to enhance the richness of the data. -After pre-processing, we first divided each dataset by store and then split the data for each store into training and test sets. Specifically: +On various tabular datasets, we initially evaluate the performance of identifying and reusing learnwares from the learnware market that share the same feature space as the user's tasks. Additionally, since tabular tasks often come from heterogeneous feature spaces, we also assess the identification and reuse of learnwares from different feature spaces. -- For PFS, the test set consisted of the last month's data from each store. -- For M5, we designated the final 28 days' data from each store as the test set. -- For Corporacion, the test set was composed of the last 16 days of data from each store. +Settings +------------------ +Our study utilize three public datasets in the field of sales forecasting: `Predict Future Sales (PFS) `_, `M5 Forecasting (M5) `_ and `Corporacion `_. To enrich the data, we apply diverse feature engineering methods to these datasets. Then we divide each dataset by store and further split the data for each store into training and test sets. A LightGBM is trained on each Corporacion and PFS training set, while the test sets and M5 datasets are reversed to construct user tasks. This results in an experimental market consisting of 265 learnwares, encompassing five types of feature spaces and two types of label spaces. All these learnwares have been uploaded to the learnware dock system. -In the submitting stage, the Corporacion dataset's 55 stores are regarded as 165 uploaders, each employing one of three different feature engineering methods. -For the PFS dataset, 100 uploaders are established, each using one of two feature engineering approaches. -These uploaders then utilize their respective stores' training data to develop LightGBM models. -As a result, the learnware market comprises 265 learnwares, derived from five types of feature spaces and two types of label spaces +Baseline algorithms +-------------------- -Based on the specific design of user tasks, our experiments were primarily categorized into two types: +The most basic way to reuse a learnware is Top-1 reuser, which directly uses the single learnware chosen by RKME specification. Besides, we implement two data-free reusers and two data-dependent reusers that works on single or multiple helpful learnwares identified from the market. When users have no labeled data, JobSelector reuser selects different learnwares for different samples by training a job selector classifier; AverageEnsemble reuser uses an ensemble method to make predictions. In cases where users possess both test data and limited labeled training data, EnsemblePruning reuser selectively ensembles a subset of learnwares to choose the ones that are most suitable for the user's task; FeatureAugment reuser regards each received learnware as a feature augmentor, taking its output as a new feature and then builds a simple model on the augmented feature set. JobSelector and FeatureAugment are only effective for tabular data, while others are also useful for text and image data. -- ``homogeneous experiments`` are designed to evaluate performance when users can reuse learnwares in the learnware market that have the same feature space as their tasks(homogeneous learnwares). - This contributes to showing the effectiveness of using learnwares that align closely with the user's specific requirements. - -- ``heterogeneous experiments`` aim to evaluate the performance of identifying and reusing helpful heterogeneous learnwares in situations where - no available learnwares match the feature space of the user's task. This helps to highlight the potential of learnwares for applications beyond their original purpose. +Homogeneous Cases +------------------ -Homogeneous Tabular Dataset ------------------------------ +In the homogeneous cases, the 53 stores within the PFS dataset function as 53 individual users. Each store utilizes its own test data as user data and applies the same feature engineering approach used in the learnware market. These users could subsequently search for homogeneous learnwares within the market that possessed the same feature spaces as their tasks. -In homogeneous experiments, the 55 stores in the Corporacion dataset are considered as 55 users. Each store uses the same feature engineering method -and their own test set as user data. These users then search for and reuse homogeneous learnwares in the market which exactly match the feature spaces of their tasks. +We conduct a comparison among different baseline algorithms when the users have no labeled data or limited amounts of labeled data. The average losses over all users are illustrated in the table below. It shows that unlabeled methods are much better than random choosing and deploying one learnware from the market. -The Mean Squared Error (MSE) of search and reuse across all users is presented in the table below: +-----------------------------------+---------------------+ | Setting | MSE | +===================================+=====================+ -| Mean in Market (Single) | 0.331 | +| Mean in Market (Single) | 0.897 | +-----------------------------------+---------------------+ -| Best in Market (Single) | 0.151 | +| Best in Market (Single) | 0.756 | +-----------------------------------+---------------------+ -| Top-1 Reuse (Single) | 0.280 | +| Top-1 Reuse (Single) | 0.830 | +-----------------------------------+---------------------+ -| Job Selector Reuse (Multiple) | 0.274 | +| Job Selector Reuse (Multiple) | 0.848 | +-----------------------------------+---------------------+ -| Average Ensemble Reuse (Multiple) | 0.267 | +| Average Ensemble Reuse (Multiple) | 0.816 | +-----------------------------------+---------------------+ -When users have both test data and limited training data derived from their original data, reusing single or multiple searched learnwares from the market can often yield -better results than training models from scratch on limited training data. We present the change curves in MSE for the user's self-trained model, as well as for the Feature Augmentation single learnware reuse method and the Ensemble Pruning multiple learnware reuse method. -These curves display their performance on the user's test data as the amount of labeled training data increases. -The average results across 55 users are depicted in the figure below: +The figure below showcases the results for different amounts of labeled data provided by the user; for each user, we conducted multiple experiments repeatedly and calculated the mean and standard deviation of the losses; the average losses over all users are illustrated in the figure. It illustrates that when users have limited training data, identifying and reusing single or multiple learnwares yields superior performance compared to user's self-trained models. -.. image:: ../_static/img/table_homo_labeled.png +.. image:: ../_static/img/Homo_labeled_curves.svg :align: center - :alt: Table Homo Limited Labeled Data - -The figure clearly shows that when users have limited training data, reusing single or multiple table learnwares outperforms the user's own model. -This highlights the advantage of reusing learnwares in substantially reducing the need for large training datasets and achieving better outcomes with restricted user training data. - Heterogeneous Tabular Dataset ------------------------------ -In heterogeneous experiments, the learnware market would recommend helpful heterogeneous learnwares with different feature spaces with -the user tasks. Based on whether there are learnwares in the market that handle tasks similar to the user's task, the experiments can be further subdivided into the following two types: +Based on the similarity of tasks between the market's learnwares and the users, the heterogeneous cases can be further categorized into different feature engineering and different task scenarios. -Cross Feature Space Experiments +Different Feature Engineering Scenarios ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -We designate the 41 stores in the PFS dataset as users, creating their user data with an alternative feature engineering approach that varies from the methods employed by learnwares in the market. -Consequently, while the market's learnwares from the PFS dataset undertake tasks very similar to our users, the feature spaces do not match exactly. In this experimental configuration, -we tested various heterogeneous learnware reuse methods (without using user's labeled data) and compared them to the user's self-trained model based on a small amount of training data. -The average MSE performance across 41 users are as follows: +We consider the 41 stores within the PFS dataset as users, generating their user data using a unique feature engineering approach that differ from the methods employed by the learnwares in the market. As a result, while some learnwares in the market are also designed for the PFS dataset, the feature spaces do not align exactly. + +In this experimental setup, we examine various data-free reusers. The results in the following table indicate that even when users lack labeled data, the market exhibits strong performance, particularly with the AverageEnsemble method that reuses multiple learnwares. + +-----------------------------------+---------------------+ | Setting | MSE | +===================================+=====================+ | Mean in Market (Single) | 1.459 | +-----------------------------------+---------------------+ -| Best in Market (Single) | 1.226 | +| Best in Market (Single) | 1.038 | +-----------------------------------+---------------------+ -| Top-1 Reuse (Single) | 1.407 | +| Top-1 Reuse (Single) | 1.105 | +-----------------------------------+---------------------+ -| Average Ensemble Reuse (Multiple) | 1.312 | -+-----------------------------------+---------------------+ -| User model with 50 labeled data | 1.267 | +| Average Ensemble Reuse (Multiple) | 1.081 | +-----------------------------------+---------------------+ -From the results, it is noticeable that the learnware market still perform quite well even when users lack labeled data, -provided it includes learnwares addressing tasks that are similar but not identical to the user's. -In these instances, the market's effectiveness can match or even rival scenarios where users have access to a limited quantity of labeled data. -Cross Task experiments +Different Task Scenarios ^^^^^^^^^^^^^^^^^^^^^^^ -Here we have chosen the 10 stores from the M5 dataset to act as users. Although the broad task of sales forecasting is similar to the tasks addressed by the learnwares in the market, -there are no learnwares available that directly cater to the M5 sales forecasting requirements. All learnwares show variations in both feature and label spaces compared to the tasks of M5 users. -We present the change curves in RMSE for the user's self-trained model and several learnware reuse methods. -These curves display their performance on the user's test data as the amount of labeled training data increases. -The average results across 10 users are depicted in the figure below: +We employ three distinct feature engineering methods on all the ten stores from the M5 dataset, resulting in a total of 30 users. Although the overall task of sales forecasting aligns with the tasks addressed by the learnwares in the market, there are no learnwares specifically designed to satisfy the M5 sales forecasting requirements. + +In the following figure, we present the loss curves for the user's self-trained model and several learnware reuse methods. It is evident that heterogeneous learnwares prove beneficial with a limited amount of the user's labeled data, facilitating better alignment with the user's specific task. -.. image:: ../_static/img/table_hetero_labeled.png +.. image:: ../_static/img/Hetero_labeled_curves.svg :align: center - :alt: Table Hetero Limited Labeled Data -We can observe that heterogeneous learnwares are beneficial when there's a limited amount of the user's labeled training data available, -aiding in better alignment with the user's specific task. This underscores the potential of learnwares to be applied to tasks beyond their original purpose. Image Data Experiment ========================= -For the CIFAR-10 dataset, we sampled the training set unevenly by category and constructed unbalanced training datasets for the 50 learnwares that contained only some of the categories. This makes it unlikely that there exists any learnware in the learnware market that can accurately handle all categories of data; only the learnware whose training data is closest to the data distribution of the target task is likely to perform well on the target task. Specifically, the probability of each category being sampled obeys a random multinomial distribution, with a non-zero probability of sampling on only 4 categories, and the sampling ratio is 0.4: 0.4: 0.1: 0.1. Ultimately, the training set for each learnware contains 12,000 samples covering the data of 4 categories in CIFAR-10. +Second, we assess our system on image datasets. It is worth noting that images of different sizes could be standardized through resizing, eliminating the need to consider heterogeneous feature cases. -We constructed 50 target tasks using data from the test set of CIFAR-10. Similar to constructing the training set for the learnwares, in order to allow for some variation between tasks, we sampled the test set unevenly. Specifically, the probability of each category being sampled obeys a random multinomial distribution, with non-zero sampling probability on 6 categories, and the sampling ratio is 0.3: 0.3: 0.1: 0.1: 0.1: 0.1. Ultimately, each target task contains 3000 samples covering the data of 6 categories in CIFAR-10. +Settings +---------------- + +We choose the famous image classification dataset [CIFAR-10](https://www.cs.toronto.edu/~kriz/cifar.html), which consists of 60000 32x32 color images in 10 classes. A total of 50 learnwares are uploaded: each learnware contains a convolutional neural network trained on an unbalanced subset that includs 12000 samples from four categories with a sampling ratio of $0.4:0.4:0.1:0.1$. +A total of 100 user tasks are tested and each user task consists of 3000 samples of CIFAR-10 with six categories with a sampling ratio of $0.3:0.3:0.1:0.1:0.1:0.1$. + + +Results +------------------- +We assess the average performance of various methods using 1 - Accuracy as the loss metric. The following table and figure show that when users face a scarcity of labeled data or possess only a limited amount of it (less than 2000 instances), leveraging the learnware market can yield good performances. -With this experimental setup, we evaluated the performance of RKME Image using 1 - Accuracy as the loss. +-----------------------------------+---------------------+ | Setting | Accuracy | @@ -150,37 +127,25 @@ With this experimental setup, we evaluated the performance of RKME Image using 1 | Average Ensemble Reuse (Multiple) | 0.310 | +-----------------------------------+---------------------+ -In some specific settings, the user will have a small number of labelled samples. In such settings, learning the weight of selected learnwares on a limited number of labelled samples can result in a better performance than training directly on a limited number of labelled samples. -.. image:: ../_static/img/image_labeled.svg +.. image:: ../_static/img/image_labeled_curves.svg :align: center Text Data Experiment ========================== -Datasets ------------------- -We conducted experiments on the widely used text benchmark dataset: `20-newsgroup `_. -20-newsgroup is a renowned text classification benchmark with a hierarchical structure, featuring 5 superclasses {comp, rec, sci, talk, misc}. - -In the submitting stage, we enumerated all combinations of three superclasses from the five available, randomly sampling 50% of each combination from the training set to create datasets for 50 uploaders. +Finally, we evaluate our system on text datasets. Text data naturally exhibit feature heterogeneity, but this issue can be addressed by applying a sentence embedding extractor. -In the deploying stage, we considered all combinations of two superclasses out of the five, selecting all data for each combination from the testing set as a test dataset for one user. This resulted in 10 users. -The user's own training data was generated using the same sampling procedure as the user test data, despite originating from the training dataset. - -Model training comprised two parts: the first part involved training a tfidf feature extractor, and the second part used the extracted text feature vectors to train a naive Bayes classifier. - -Our experiments comprises two components: +Settings +------------------ -* ``unlabeled_text_example`` is designed to evaluate performance when users possess only testing data, searching and reusing learnware available in the market. -* ``labeled_text_example`` aims to assess performance when users have both testing and limited training data, searching and reusing learnware directly from the market instead of training a model from scratch. This helps determine the amount of training data saved for the user. +We conduct experiments on the well-known text classification dataset: [20-newsgroup](http://qwone.com/~jason/20Newsgroups/), which consists approximately 20000 newsgroup documents partitioned across 20 different newsgroups. +Similar to the image experiments, a total of 50 learnwares are uploaded. Each learnware is trained on a subset that includes only half of the samples from three superclasses and the model in it is a tf-idf feature extractor combined with a naive Bayes classifier. We define 10 user tasks, and each of them encompasses two superclasses. Results ---------------- -* ``unlabeled_text_example``: - -The table below presents the mean accuracy of search and reuse across all users: +The results are depicted in the following table and figure. Similarly, even when no labeled data is provided, the performance achieved through learnware identification and reuse can match that of the best learnware in the market. Additionally, utilizing the learnware market allows for a reduction of approximately 2000 samples compared to training models from scratch. +-----------------------------------+---------------------+ | Setting | Accuracy | @@ -196,29 +161,29 @@ The table below presents the mean accuracy of search and reuse across all users: | Average Ensemble Reuse (Multiple) | 0.862 | +-----------------------------------+---------------------+ -* ``labeled_text_example``: - -We present the change curves in classification error rates for both the user's self-trained model and the multiple learnware reuse(EnsemblePrune), showcasing their performance on the user's test data as the user's training data increases. The average results across 10 users are depicted below: -.. image:: ../_static/img/text_labeled.svg +.. image:: ../_static/img/text_labeled_curves.svg :align: center - :alt: Results on Text Experimental Scenario - - -From the figure above, it is evident that when the user's own training data is limited, the performance of multiple learnware reuse surpasses that of the user's own model. As the user's training data grows, it is expected that the user's model will eventually outperform the learnware reuse. This underscores the value of reusing learnware to significantly conserve training data and achieve superior performance when user training data is limited. Get Start Examples ========================= -Examples for `Tabular, Text` and `Image` data sets are available at `Learnware Examples `_. You can run { main.py } directly to reproduce related experiments. +Examples for `Tabular, Text` and `Image` data sets are available at `Learnware Examples `_. You can run { workflow.py } directly to reproduce related experiments. We utilize the `fire` module to construct our experiments. +Table Examples +------------------ +* `python workflow.py unlabeled_homo_table_example`: Executes the unlabeled_homo_table_example experiment; the results will be printed in the terminal. +* `python workflow.py labeled_homo_table_example`: Executes the labeled_homo_table_example experiment; result curves will be automatically saved in the `figs` directory. +* `python workflow.py cross_feat_eng_hetero_table_example`: Executes the cross_feat_eng_hetero_table_example experiment; the results will be printed in the terminal. +* `python workflow.py cross_task_hetero_table_example`: Executes the cross_task_hetero_table_example experiment; result curves will be automatically saved in the `figs` directory. + Text Examples ------------------ You can execute the experiment with the following commands: -* `python main.py unlabeled_text_example`: Executes the unlabeled_text_example experiment; the results will be printed in the terminal. -* `python main.py labeled_text_example`: Executes the labeled_text_example experiment; result curves will be automatically saved in the `figs` directory. +* `python workflow.py unlabeled_text_example`: Executes the unlabeled_text_example experiment; the results will be printed in the terminal. +* `python workflow.py labeled_text_example`: Executes the labeled_text_example experiment; result curves will be automatically saved in the `figs` directory. Image Examples ------------------ diff --git a/docs/start/install.rst b/docs/start/install.rst index 3b80e37..2ac1d36 100644 --- a/docs/start/install.rst +++ b/docs/start/install.rst @@ -8,9 +8,9 @@ Installation Guide =================================== .. note:: - The ``learnware`` package supports `Windows`, `Linux`. It's recommended to use ``Learnware`` in `Linux`. ``Learnware`` supports Python3, which is up to Python3.11. + The ``learnware`` package supports `Windows`, `Linux`. It's recommended to use ``learnware`` in `Linux`. This package supports Python3, which is up to Python3.11. -Users can easily install ``Learnware`` by pip according to the following command: +Users can easily install ``learnware`` by pip according to the following command: .. code-block:: bash @@ -29,10 +29,10 @@ In the ``learnware`` package, besides the base classes, many core functionalitie Install ``learnware`` Package From Source ========================================== -Also, Users can install ``Learnware`` by the source code according to the following steps: +Also, Users can install ``learnware`` by the source code according to the following steps: -- Enter the root directory of ``Learnware``, in which the file ``setup.py`` exists. -- Then, please execute the following command to install the environment dependencies and install ``Learnware``: +- Enter the root directory of this project, in which the file ``setup.py`` exists. +- Then, please execute the following command to install the environment dependencies and install ``learnware``: .. code-block:: bash diff --git a/docs/start/intro.rst b/docs/start/intro.rst index 9d0e753..947d081 100644 --- a/docs/start/intro.rst +++ b/docs/start/intro.rst @@ -76,11 +76,44 @@ Procedure of Learnware Paradigm :align: center -Learnware Package Design -========================== +Framework and Architecture Design +================================== .. image:: ../_static/img/learnware_framework.svg :align: center -At the workflow level, the ``learnware`` package consists of ``Submitting Stage`` and ``Deploying Stage``. -At the module level, the ``learnware`` package is a platform that consists of above components. The components are designed as loose-coupled modules and each component could be used stand-alone. +The architecture is designed based on the guidelines including *decoupling*, *autonomy*, *reusability*, and *scalability*. The above architecture diagram illustrates the architecture and framework from the perspectives of both modules and workflows. + +- At the workflow level, the ``learnware`` package consists of ``Submitting Stage`` and ``Deploying Stage``. + ++---------------------+-------------------------------------------------------------------------------------------------------------------+ +| Module | Workflow | ++=====================+===================================================================================================================+ +| ``Submitting Stage``| The learnware developers submit learnwares to the learnware market, which conducts usability checks and further | +| | organization of these learnwares. | ++---------------------+-------------------------------------------------------------------------------------------------------------------+ +| ``Deploying Stage`` | The `learnware` package identifies learnwares according to users’ task requirements and provides efficient | +| | reuse and deployment methods. | ++---------------------+-------------------------------------------------------------------------------------------------------------------+ + +- At the module level, the ``learnware`` package is a platform that consists of ``Learnware``, ``Market``, ``Specification``, ``Model``, ``Reuse``, and ``Interface`` modules. + ++------------------+------------------------------------------------------------------------------------------------------------+ +| Module | Description | ++==================+============================================================================================================+ +| ``Learnware`` | The specific learnware, consisting of specification module, and user model module. | ++------------------+------------------------------------------------------------------------------------------------------------+ +| ``Market`` | Designed for learnware organization, identification, and usability testing. | ++------------------+------------------------------------------------------------------------------------------------------------+ +| ``Specification``| Generating and storing statistical and semantic information of learnware, which can be used for learnware | +| | search and reuse. | ++------------------+------------------------------------------------------------------------------------------------------------+ +| ``Model`` | Including the base model and the model container, which can provide unified interfaces and automatically | +| | create isolated runtime environments. | ++------------------+------------------------------------------------------------------------------------------------------------+ +| ``Reuse`` | Including the data-free reuser, data-dependent reuser, and aligner, which can deploy and reuse learnware | +| | for user tasks. | ++------------------+------------------------------------------------------------------------------------------------------------+ +| ``Interface`` | The interface for network communication with the `Beimingwu` backend. | ++------------------+------------------------------------------------------------------------------------------------------------+ + diff --git a/docs/start/quick.rst b/docs/start/quick.rst index 2d714a2..aedbb6c 100644 --- a/docs/start/quick.rst +++ b/docs/start/quick.rst @@ -14,7 +14,7 @@ and utilizing ``Learnware`` to handle user tasks. Installation ==================== -Learnware is currently hosted on `PyPI `_. You can easily intsall ``Learnware`` by following these steps: +Learnware is currently hosted on `PyPI `_. You can easily intsall the ``learnware`` package by following these steps: .. code-block:: bash @@ -32,14 +32,14 @@ In the ``learnware`` package, besides the base classes, many core functionalitie Prepare Learnware ==================== -In learnware ``learnware`` package, each learnware is encapsulated in a ``zip`` package, which should contain at least the following four files: +In the ``learnware`` package, each learnware is encapsulated in a ``zip`` package, which should contain at least the following four files: - ``learnware.yaml``: learnware configuration file. - ``__init__.py``: methods for using the model. - ``stat.json``: the statistical specification of the learnware. Its filename can be customized and recorded in learnware.yaml. - ``environment.yaml`` or ``requirements.txt``: specifies the environment for the model. -To facilitate the construction of a learnware, we provide a `Learnware Template `_ that the users can use as a basis for building your own learnware. We've also detailed the format of the learnware ``zip`` package in `Learnware Preparation<../workflows/upload:prepare-learnware>`. +To facilitate the construction of a learnware, we provide a `Learnware Template `_ that the users can use as a basis for building your own learnware. We've also detailed the format of the learnware ``zip`` package in `Learnware Preparation <../workflows/upload:prepare-learnware>`_. Learnware Package Workflow ============================ @@ -119,7 +119,7 @@ If you decide in favor of porviding your own statistical specification file, ``s the ``Learnware Market`` can further refine the selection of learnwares from the previous step. This second-stage search leverages statistical information to identify one or more learnwares that are most likely to be beneficial for your task. -For example, the code below executes learnware search when using Reduced Set Kernel Embedding as the statistical specification: +For example, the code below executes learnware search when using Reduced Kernel Mean Embedding (RKME) as the statistical specification: .. code-block:: python diff --git a/docs/workflows/client.rst b/docs/workflows/client.rst index 69114ad..0482a3c 100644 --- a/docs/workflows/client.rst +++ b/docs/workflows/client.rst @@ -81,7 +81,7 @@ Ensure that the input parameters for the semantic specification fall within the * "task_type" must be within the range of ``key=SemanticSpecificationKey.TASK_TYPE``. * "library_type" must be within the range of ``key=SemanticSpecificationKey.LIBRARY_TYPE``. * "scenarios" must be a subset of ``key=SemanticSpecificationKey.SENARIOS``. -* "license" must be a subset of ``key=SemanticSpecificationKey.LICENSE``. +* "license" must be within the range of ``key=SemanticSpecificationKey.LICENSE``. * When "data_type" is set to "Table", it is necessary to provide "input_description". * When "task_type" is either "Classification" or "Regression", it is necessary to provide "output_description". diff --git a/docs/workflows/reuse.rst b/docs/workflows/reuse.rst index 8f660df..ef729d0 100644 --- a/docs/workflows/reuse.rst +++ b/docs/workflows/reuse.rst @@ -4,7 +4,7 @@ Learnwares Reuse ``Learnware Reuser`` is a ``Python API`` that offers a variety of convenient tools for learnware reuse. Users can reuse a single learnware, combination of multiple learnwares, and heterogeneous learnwares using these tools efficiently, thereby saving the laborious time and effort of building models from scratch. There are mainly two types of -reuse tools, based on whether user has gathered a small amount of labeled data beforehand: (1) direct reuse and (2) customized reuse based on labeled data. +reuse tools, based on whether user has gathered a small amount of labeled data beforehand: (1) data-free reuser and (2) data-dependent reuser. .. note:: @@ -15,7 +15,16 @@ Homo Reuse This part introduces baseline methods for reusing homogeneous learnwares to make predictions on unlabeled data. -Direct reuse of Learnware +The most basic way is to directly use a single learnware. + +.. code:: python + + # learnware is a single learnware in the search results + # test_x is the user's data for prediction + # predict_y is the prediction result of the reused learnware + predict_y = learnware.predict(user_data=test_x) + +Data-Free Reuser -------------------------- - ``JobSelector`` selects different learnwares for different data by training a ``job selector`` classifier. The following code shows how to use it: @@ -49,7 +58,7 @@ Direct reuse of Learnware ensemble_predict_y = reuse_ensemble.predict(user_data=test_x) -Reusing Learnware with Labeled Data +Data-Dependent Reuser ------------------------------------ When users have a small amount of labeled data, they can also adapt/polish the received learnware(s) by reusing them with the labeled data, gaining even better performance. @@ -143,10 +152,10 @@ Run the following codes to try run a learnware with ``Model Container``: from learnware.learnware import Learnware - with LearnwaresContainer(learnware, mode="conda") as env_container: # Let learnware be instance of Learnware Class, and its input shape is (20, 204) + # Let learnware be instance of Learnware Class, test_x be an input array + with LearnwaresContainer(learnware, mode="conda") as env_container: learnware = env_container.get_learnwares_with_container()[0] - input_array = np.random.random(size=(20, 204)) - print(learnware.predict(input_array)) + print(learnware.predict(test_x)) The ``mode`` parameter has two options, each for a specific learnware environment loading method: diff --git a/docs/workflows/upload.rst b/docs/workflows/upload.rst index 09d47a2..382843a 100644 --- a/docs/workflows/upload.rst +++ b/docs/workflows/upload.rst @@ -1,6 +1,6 @@ .. _submit: ========================================== -Learnware Preparation and Uoloading +Learnware Preparation and Uploading ========================================== In this section, we provide a comprehensive guide on submitting your custom learnware to the ``Learnware Market``. @@ -66,13 +66,13 @@ Input and Output Dimensions File Path ^^^^^^^^^^^^^^^^^^ -If you need to load certain files within the zip package in the ``__init__.py`` file (and any other Python files that may be involved), please follow the method shown in the template above about obtaining the ``model_path``: +If you need to load certain files within the ``zip`` package in the ``__init__.py`` file (and any other Python files that may be involved), please follow the method shown in the template above about obtaining the ``model_path``: - First, obtain the root directory path of the entire package by getting ``dir_path``. - - - Then, based on the specific file's relative location within the package, obtain the specific file's path, ``model_path``. + - Then, based on the specific file's relative location within the package, obtain the specific file's path, ``model_path``. Module Imports ^^^^^^^^^^^^^^^^^^ -Please note that module imports between Python files within the zip package should be done using **relative imports**. For instance: +Please note that module imports between Python files within the ``zip`` package should be done using **relative imports**. For instance: .. code-block:: python @@ -108,15 +108,15 @@ This file is used to specify the class name (``MyModel``) in the model invocatio .. code-block:: yaml model: - class_name: MyModel - kwargs: {} + class_name: MyModel + kwargs: {} stat_specifications: - - module_path: learnware.specification + - module_path: learnware.specification class_name: RKMETableSpecification file_name: stat.json kwargs: {} -Please note that the statistical specification class name for different data types ``['table', 'image', 'text']`` is ``[RKMETableSpecification, RKMEImageSpecification, RKMETextSpecification]``, respectively. +Please note that the statistical specification class name for different data types ``['table', 'image', 'text']`` is ``[RKMETableSpecification, RKMEImageSpecification, RKMETextSpecification]``, respectively. ``kwargs`` are reserved ports and do not need to be entered. Model Runtime Dependent File -------------------------------------------- @@ -240,6 +240,7 @@ The semantic specification succinctly describes the features of your task and mo task_type="Classification", library_type="Scikit-learn", scenarios=["Business", "Financial"], + license="MIT", input_description=input_description, output_description=output_description, ) @@ -268,7 +269,7 @@ you can effortlessly upload your learnware to the ``Learnware Market`` as follow Here, ``zip_path`` refers to the directory of your learnware ``zip`` package. ``learnware_id`` indicates the id assigned by ``Learnware Market``, and the ``learnware_status`` indicates the check status for learnware. .. note:: - The learnware ``zip`` package uploaded into ``LearnwareMarket`` will be checked semantically and statistically, and ``add_learnware`` will return the concrete check status. The check status ``BaseChecker.INVALID_LEARNWARE`` indicates the learnware did not pass the check. For more details about learnware checker, please refer to `Learnware Market <../components/market.html#easy-checker>` + The learnware ``zip`` package uploaded into ``LearnwareMarket`` will be checked semantically and statistically, and ``add_learnware`` will return the concrete check status. The check status ``BaseChecker.INVALID_LEARNWARE`` indicates the learnware did not pass the check. For more details about learnware checker, please refer to `Learnware Market <../components/market.html#easy-checker>`_ Remove Learnware ================== @@ -279,6 +280,6 @@ from the ``Learnware Market``: .. code-block:: python - easy_market.delete_learnware(learnware_id) + demo_market.delete_learnware(learnware_id) -Here, ``learnware_id`` refers to the market ID of the learnware to be removed. +Here, ``learnware_id`` is a string that refers to the market ID of the learnware to be removed. diff --git a/docs/README_zh.md b/examples/dataset_table_workflow/README.md similarity index 100% rename from docs/README_zh.md rename to examples/dataset_table_workflow/README.md diff --git a/examples/dataset_table_workflow/requirements.txt b/examples/dataset_table_workflow/requirements.txt new file mode 100644 index 0000000..fb912a3 --- /dev/null +++ b/examples/dataset_table_workflow/requirements.txt @@ -0,0 +1 @@ +lightgbm==3.3.5 \ No newline at end of file diff --git a/examples/dataset_table_workflow/workflow.py b/examples/dataset_table_workflow/workflow.py index dee3fc9..9352e2a 100644 --- a/examples/dataset_table_workflow/workflow.py +++ b/examples/dataset_table_workflow/workflow.py @@ -3,47 +3,40 @@ import fire from learnware.logger import get_module_logger from homo import HomogeneousDatasetWorkflow from hetero import HeterogeneousDatasetWorkflow -from config import homo_table_benchmark_config, hetero_cross_feat_eng_benchmark_config, hetero_cross_task_benchmark_config -from utils import set_seed +from config import ( + homo_table_benchmark_config, + hetero_cross_feat_eng_benchmark_config, + hetero_cross_task_benchmark_config, +) logger = get_module_logger("base_table", level="INFO") class TableDatasetWorkflow: - def unlabeled_homo_table_example(self): + def unlabeled_homo_table_example(self, rebuild=True): workflow = HomogeneousDatasetWorkflow( - benchmark_config=homo_table_benchmark_config, - name="easy", - rebuild=True + benchmark_config=homo_table_benchmark_config, name="easy", rebuild=rebuild ) workflow.unlabeled_homo_table_example() - def labeled_homo_table_example(self, skip_test=False): + def labeled_homo_table_example(self, skip_test=False, rebuild=True): workflow = HomogeneousDatasetWorkflow( - benchmark_config=homo_table_benchmark_config, - name="easy", - rebuild=False + benchmark_config=homo_table_benchmark_config, name="easy", rebuild=rebuild ) workflow.labeled_homo_table_example(skip_test=skip_test) - - def cross_feat_eng_hetero_table_example(self): + + def cross_feat_eng_hetero_table_example(self, rebuild=True, retrain=True): workflow = HeterogeneousDatasetWorkflow( - benchmark_config=hetero_cross_feat_eng_benchmark_config, - name="hetero", - rebuild=True, - retrain=True + benchmark_config=hetero_cross_feat_eng_benchmark_config, name="hetero", rebuild=rebuild, retrain=retrain ) workflow.unlabeled_hetero_table_example() - def cross_task_hetero_table_example(self, skip_test=False): + def cross_task_hetero_table_example(self, skip_test=False, rebuild=True, retrain=True): workflow = HeterogeneousDatasetWorkflow( - benchmark_config=hetero_cross_task_benchmark_config, - name="hetero", - rebuild=True, - retrain=True + benchmark_config=hetero_cross_task_benchmark_config, name="hetero", rebuild=rebuild, retrain=retrain ) workflow.labeled_hetero_table_example(skip_test=skip_test) if __name__ == "__main__": - fire.Fire(TableDatasetWorkflow) \ No newline at end of file + fire.Fire(TableDatasetWorkflow) diff --git a/learnware/__init__.py b/learnware/__init__.py index b27c55e..8c8c768 100644 --- a/learnware/__init__.py +++ b/learnware/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.2.0.9" +__version__ = "0.3.1" import json import os diff --git a/learnware/client/__init__.py b/learnware/client/__init__.py index 9849835..696e6c7 100644 --- a/learnware/client/__init__.py +++ b/learnware/client/__init__.py @@ -1 +1,3 @@ from .learnware_client import LearnwareClient, SemanticSpecificationKey + +__all__ = ["LearnwareClient", "SemanticSpecificationKey"] diff --git a/learnware/market/__init__.py b/learnware/market/__init__.py index fba3552..6e9e718 100644 --- a/learnware/market/__init__.py +++ b/learnware/market/__init__.py @@ -6,3 +6,24 @@ from .evolve import EvolvedOrganizer from .evolve_anchor import EvolvedAnchoredOrganizer from .heterogeneous import HeteroMapTableOrganizer, HeteroSearcher from .module import instantiate_learnware_market + +__all__ = [ + "AnchoredOrganizer", + "AnchoredSearcher", + "AnchoredUserInfo", + "BaseChecker", + "BaseOrganizer", + "BaseSearcher", + "BaseUserInfo", + "LearnwareMarket", + "CondaChecker", + "EasyOrganizer", + "EasySearcher", + "EasySemanticChecker", + "EasyStatChecker", + "EvolvedOrganizer", + "EvolvedAnchoredOrganizer", + "HeteroMapTableOrganizer", + "HeteroSearcher", + "instantiate_learnware_market", +] diff --git a/learnware/market/anchor/__init__.py b/learnware/market/anchor/__init__.py index c453220..8125050 100644 --- a/learnware/market/anchor/__init__.py +++ b/learnware/market/anchor/__init__.py @@ -10,3 +10,5 @@ if not is_torch_available(verbose=False): logger.error("AnchoredSearcher is not available because 'torch' is not installed!") else: from .searcher import AnchoredSearcher + +__all__ = ["AnchoredOrganizer", "AnchoredUserInfo", "AnchoredSearcher"] diff --git a/learnware/market/easy/__init__.py b/learnware/market/easy/__init__.py index e2d58e5..bbedeef 100644 --- a/learnware/market/easy/__init__.py +++ b/learnware/market/easy/__init__.py @@ -8,7 +8,20 @@ if not is_torch_available(verbose=False): EasySearcher = None EasySemanticChecker = None EasyStatChecker = None + EasyExactSemanticSearcher = None + EasyFuzzSemanticSearcher = None + EasyStatSearcher = None logger.error("EasySeacher and EasyChecker are not available because 'torch' is not installed!") else: from .checker import EasySemanticChecker, EasyStatChecker from .searcher import EasyExactSemanticSearcher, EasyFuzzSemanticSearcher, EasySearcher, EasyStatSearcher + +__all__ = [ + "EasyOrganizer", + "EasySemanticChecker", + "EasyStatChecker", + "EasyExactSemanticSearcher", + "EasyFuzzSemanticSearcher", + "EasySearcher", + "EasyStatSearcher", +] diff --git a/learnware/market/evolve/__init__.py b/learnware/market/evolve/__init__.py index e0069c5..3f88349 100644 --- a/learnware/market/evolve/__init__.py +++ b/learnware/market/evolve/__init__.py @@ -1 +1,3 @@ from .organizer import EvolvedOrganizer + +__all__ = ["EvolvedOrganizer"] diff --git a/learnware/market/evolve_anchor/__init__.py b/learnware/market/evolve_anchor/__init__.py index a83cc4b..9380268 100644 --- a/learnware/market/evolve_anchor/__init__.py +++ b/learnware/market/evolve_anchor/__init__.py @@ -1 +1,3 @@ from .organizer import EvolvedAnchoredOrganizer + +__all__ = ["EvolvedAnchoredOrganizer"] diff --git a/learnware/market/heterogeneous/__init__.py b/learnware/market/heterogeneous/__init__.py index 0252b0a..4162f1d 100644 --- a/learnware/market/heterogeneous/__init__.py +++ b/learnware/market/heterogeneous/__init__.py @@ -10,3 +10,5 @@ if not is_torch_available(verbose=False): else: from .organizer import HeteroMapTableOrganizer from .searcher import HeteroSearcher + +__all__ = ["HeteroMapTableOrganizer", "HeteroSearcher"] diff --git a/learnware/market/heterogeneous/organizer/hetero_map/__init__.py b/learnware/market/heterogeneous/organizer/hetero_map/__init__.py index 47978cf..dad56c6 100644 --- a/learnware/market/heterogeneous/organizer/hetero_map/__init__.py +++ b/learnware/market/heterogeneous/organizer/hetero_map/__init__.py @@ -646,3 +646,6 @@ class TransformerMultiLayer(nn.Module): for i, mod in enumerate(self.transformer_encoder): outputs = mod(outputs, src_key_padding_mask=attention_mask) return outputs + + +__all__ = ["HeteroMap", "Trainer"] diff --git a/learnware/model/__init__.py b/learnware/model/__init__.py index 7a14cda..d237fd1 100644 --- a/learnware/model/__init__.py +++ b/learnware/model/__init__.py @@ -1 +1,3 @@ from .base import BaseModel + +__all__ = ["BaseModel"] diff --git a/learnware/reuse/__init__.py b/learnware/reuse/__init__.py index 7a8d185..ed06a70 100644 --- a/learnware/reuse/__init__.py +++ b/learnware/reuse/__init__.py @@ -21,3 +21,14 @@ else: from .feature_augment import FeatureAugmentReuser from .hetero import FeatureAlignLearnware, HeteroMapAlignLearnware from .job_selector import JobSelectorReuser + +__all__ = [ + "AlignLearnware", + "BaseReuser", + "AveragingReuser", + "EnsemblePruningReuser", + "FeatureAugmentReuser", + "FeatureAlignLearnware", + "HeteroMapAlignLearnware", + "JobSelectorReuser", +] diff --git a/learnware/reuse/hetero/__init__.py b/learnware/reuse/hetero/__init__.py index 6f8ad23..ec98d64 100644 --- a/learnware/reuse/hetero/__init__.py +++ b/learnware/reuse/hetero/__init__.py @@ -1,2 +1,4 @@ from .feature_align import FeatureAlignLearnware from .hetero_map import HeteroMapAlignLearnware + +__all__ = ["FeatureAlignLearnware", "HeteroMapAlignLearnware"] diff --git a/learnware/specification/__init__.py b/learnware/specification/__init__.py index 6f50627..82246ff 100644 --- a/learnware/specification/__init__.py +++ b/learnware/specification/__init__.py @@ -24,3 +24,20 @@ else: generate_semantic_spec, generate_stat_spec, ) + +__all__ = [ + "BaseStatSpecification", + "Specification", + "RegularStatSpecification", + "RKMEImageSpecification", + "RKMEStatSpecification", + "RKMETableSpecification", + "RKMETextSpecification", + "HeteroMapTableSpecification", + "rkme_solve_qp", + "generate_rkme_image_spec", + "generate_rkme_table_spec", + "generate_rkme_text_spec", + "generate_semantic_spec", + "generate_stat_spec", +] diff --git a/learnware/specification/regular/__init__.py b/learnware/specification/regular/__init__.py index 6227607..51c7921 100644 --- a/learnware/specification/regular/__init__.py +++ b/learnware/specification/regular/__init__.py @@ -2,3 +2,12 @@ from .base import RegularStatSpecification from .image import RKMEImageSpecification from .table import RKMEStatSpecification, RKMETableSpecification, rkme_solve_qp from .text import RKMETextSpecification + +__all__ = [ + "RegularStatSpecification", + "RKMEImageSpecification", + "RKMEStatSpecification", + "RKMETableSpecification", + "rkme_solve_qp", + "RKMETextSpecification", +] diff --git a/learnware/specification/regular/image/__init__.py b/learnware/specification/regular/image/__init__.py index 9d4374f..d043176 100644 --- a/learnware/specification/regular/image/__init__.py +++ b/learnware/specification/regular/image/__init__.py @@ -8,3 +8,5 @@ if not is_torch_available(verbose=False): logger.error("RKMEImageSpecification is not available because 'torch' is not installed!") else: from .rkme import RKMEImageSpecification + +__all__ = ["RKMEImageSpecification"] diff --git a/learnware/specification/regular/table/__init__.py b/learnware/specification/regular/table/__init__.py index 47b4aaa..d5ba01d 100644 --- a/learnware/specification/regular/table/__init__.py +++ b/learnware/specification/regular/table/__init__.py @@ -12,3 +12,5 @@ if not is_torch_available(verbose=False): ) else: from .rkme import RKMEStatSpecification, RKMETableSpecification, rkme_solve_qp + +__all__ = ["RKMEStatSpecification", "RKMETableSpecification", "rkme_solve_qp"] diff --git a/learnware/specification/regular/text/__init__.py b/learnware/specification/regular/text/__init__.py index e92360e..18f2c2d 100644 --- a/learnware/specification/regular/text/__init__.py +++ b/learnware/specification/regular/text/__init__.py @@ -8,3 +8,5 @@ if not is_torch_available(verbose=False): logger.error("RKMETextSpecification is not available because 'torch' is not installed!") else: from .rkme import RKMETextSpecification + +__all__ = ["RKMETextSpecification"] diff --git a/learnware/specification/system/__init__.py b/learnware/specification/system/__init__.py index 4c286b9..d89292a 100644 --- a/learnware/specification/system/__init__.py +++ b/learnware/specification/system/__init__.py @@ -9,3 +9,5 @@ if not is_torch_available(verbose=False): logger.error("HeteroMapTableSpecification is not available because 'torch' is not installed!") else: from .hetero_table import HeteroMapTableSpecification + +__all__ = ["SystemStatSpecification", "HeteroMapTableSpecification"] diff --git a/learnware/tests/__init__.py b/learnware/tests/__init__.py index 7ba38d5..898b2fe 100644 --- a/learnware/tests/__init__.py +++ b/learnware/tests/__init__.py @@ -1 +1,3 @@ from .utils import parametrize + +__all__ = ["parametrize"] diff --git a/learnware/tests/benchmarks/__init__.py b/learnware/tests/benchmarks/__init__.py index 523a910..05609f9 100644 --- a/learnware/tests/benchmarks/__init__.py +++ b/learnware/tests/benchmarks/__init__.py @@ -2,6 +2,7 @@ import os import pickle import tempfile import zipfile +import numpy as np from dataclasses import dataclass from typing import List, Optional, Tuple, Union @@ -21,7 +22,9 @@ class Benchmark: train_y_paths: Optional[List[str]] = None extra_info_path: Optional[str] = None - def get_test_data(self, user_ids: Union[int, List[int]]): + def get_test_data( + self, user_ids: Union[int, List[int]] + ) -> Union[Tuple[np.ndarray, np.ndarray], List[Tuple[np.ndarray, np.ndarray]]]: raw_user_ids = user_ids if isinstance(user_ids, int): user_ids = [user_ids] @@ -41,7 +44,9 @@ class Benchmark: else: return ret - def get_train_data(self, user_ids: Union[int, List[int]]): + def get_train_data( + self, user_ids: Union[int, List[int]] + ) -> Optional[Union[Tuple[np.ndarray, np.ndarray], List[Tuple[np.ndarray, np.ndarray]]]]: if self.train_X_paths is None or self.train_y_paths is None: return None @@ -98,7 +103,7 @@ class LearnwareBenchmark: else: return False - def _download_data(self, download_path: str, save_path: str): + def _download_data(self, download_path: str, save_path: str) -> None: """Download data from backend Parameters @@ -128,7 +133,7 @@ class LearnwareBenchmark: """ cache_folder = os.path.join(C.cache_path, benchmark_config.name, f"{data_type}_data") if not self._check_cache_data_valid(benchmark_config, data_type): - download_path = getattr(benchmark_config, f"{data_type}_data_path", None) + download_path = getattr(benchmark_config, f"{data_type}_data_path") self._download_data(download_path, cache_folder) X_paths, y_paths = [], [] @@ -142,10 +147,15 @@ class LearnwareBenchmark: return X_paths, y_paths - def get_benchmark(self, benchmark_config: Union[str, BenchmarkConfig]): + def get_benchmark(self, benchmark_config: Union[str, BenchmarkConfig]) -> Benchmark: if isinstance(benchmark_config, str): benchmark_config = self.benchmark_configs[benchmark_config] + if not isinstance(benchmark_config, BenchmarkConfig): + raise ValueError( + "benchmark_config must be a BenchmarkConfig object or a string in benchmark_configs.keys()!" + ) + # Load test data test_X_paths, test_y_paths = self._load_cache_data(benchmark_config, "test") diff --git a/learnware/tests/benchmarks/config.py b/learnware/tests/benchmarks/config.py index e595fd3..24a8dfd 100644 --- a/learnware/tests/benchmarks/config.py +++ b/learnware/tests/benchmarks/config.py @@ -1,5 +1,5 @@ from dataclasses import dataclass -from typing import List, Optional +from typing import List, Optional, Dict @dataclass @@ -12,4 +12,4 @@ class BenchmarkConfig: extra_info_path: Optional[str] = None -benchmark_configs = {} +benchmark_configs: Dict[str, BenchmarkConfig] = {} diff --git a/learnware/utils/__init__.py b/learnware/utils/__init__.py index bde7f09..cc12acc 100644 --- a/learnware/utils/__init__.py +++ b/learnware/utils/__init__.py @@ -5,7 +5,6 @@ from .file import convert_folder_to_zipfile, read_yaml_to_dict, save_dict_to_yam from .gpu import allocate_cuda_idx, choose_device, setup_seed from .import_utils import is_torch_available from .module import get_module_by_module_path -from ..config import SystemType, get_platform def zip_learnware_folder(path: str, output_name: str): @@ -16,3 +15,15 @@ def zip_learnware_folder(path: str, output_name: str): if file.endswith(".pyc") or os.path.islink(full_path): continue zip_ref.write(full_path, arcname=os.path.relpath(full_path, path)) + + +__all__ = [ + "convert_folder_to_zipfile", + "read_yaml_to_dict", + "save_dict_to_yaml", + "allocate_cuda_idx", + "choose_device", + "setup_seed", + "is_torch_available", + "get_module_by_module_path", +] diff --git a/learnware/utils/import_utils.py b/learnware/utils/import_utils.py index 449b727..778a1a0 100644 --- a/learnware/utils/import_utils.py +++ b/learnware/utils/import_utils.py @@ -5,7 +5,7 @@ logger = get_module_logger("import_utils") def is_torch_available(verbose=False): try: - import torch + import torch # noqa: F401 except ModuleNotFoundError as err: if verbose is True: logger.warning("ModuleNotFoundError: torch is not installed, please install pytorch!") diff --git a/setup.py b/setup.py index ce4fc1e..574a3c4 100644 --- a/setup.py +++ b/setup.py @@ -89,8 +89,8 @@ if __name__ == "__main__": setup( name=NAME, version=VERSION, - license="MIT Licence", - url="https://github.com/Learnware-LAMDA/Learnware", + license="Apache-2.0 Licence", + url="https://gitee.com/beimingwu/learnware", packages=find_packages(), include_package_data=True, description=DESCRIPTION, @@ -110,8 +110,6 @@ if __name__ == "__main__": "Topic :: Scientific/Engineering", "Operating System :: POSIX :: Linux", "Operating System :: Microsoft :: Windows", - "Operating System :: MacOS", - "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10",