Skip to content

XR-Transformer refactor and enable cost-sensitive learning via XLinear API/CLI - #64

Merged
jiong-zhang merged 13 commits into
amzn:mainlinefrom
jiong-zhang:mainline
Oct 4, 2021
Merged

XR-Transformer refactor and enable cost-sensitive learning via XLinear API/CLI#64
jiong-zhang merged 13 commits into
amzn:mainlinefrom
jiong-zhang:mainline

Conversation

@jiong-zhang

Copy link
Copy Markdown
Contributor

Issue #, if available:

Description of changes:

Enable Cost-Sensitive Learning via XLinear API/CLI

  • Allow user supplied relevance matrix for leaf layer through CLI tool in pecos.xmc.xlinear.train
  • Allow user supplied relevance matrices chain via XLinear python API.

XR-Transformer refactor

  • Allow advanced control of Train/Pred params via json input.
  • Sample JSON skeleton generation CLI tool for Train/Pred params for easy edit/reproduce.
  • End2end XR-Transformer training.
  • XR-Transformer now only save the final encoder after recursive fine-tuning.
  • New CLI tool for generating embeddings pecos.xmc.xtransformer.encode
  • Updated README.md with new API/CLI tools and Python example.
  • Replace python tokenizers with new fast tokenizers using huggingface's C implementation.

Others

  • TrainParams for HierarchicalKMeans
  • Add proper unit tests for new functionalities.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@jiong-zhang
jiong-zhang marked this pull request as ready for review September 28, 2021 04:27
Comment thread pecos/xmc/base.py
Comment thread pecos/xmc/base.py Outdated
if "man" in negative_sampling_scheme:
M += smat_util.binarized(M_pred)
cur_prob = MLProblem(cur_prob.pX, Y, C=C, M=M, threads=matmul_threads)
cur_prob = MLProblem(cur_prob.pX, Y, R=R, C=C, M=M, threads=matmul_threads)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We can merge line 1400 and 1415 into one, if moving line 1415 outside of else?

Comment thread pecos/xmc/xlinear/model.py Outdated
nr_splits: int = 2
min_codes: int = None # type: ignore
shallow: bool = False
relevance_norm: str = "l1"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

as discussed in last meeting, should we use rel_induce and rel_norm to control the hierarchical bahavior of cost-sensitive learning?

Comment thread pecos/xmc/xlinear/model.py Outdated
X,
Y,
C=None,
relevance_matrices=None,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we support only a single relevance matrix, but not dictionary form?

Comment thread pecos/xmc/xtransformer/README.md Outdated
@@ -1,44 +1,104 @@
# PECOS eXtreme Multi-label Classification: XTransformer
# PECOS eXtreme Multi-label Classification: X(R)-Transformer

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's just use XR-Transformer ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also, we can include the .bib now?

Comment thread pecos/xmc/xtransformer/README.md Outdated
You can also get the fine-tuned text embeddings via:
```bash
> python3 -m pecos.xmc.xlinear.evaluate -y ${Y_path} -p ${Yp_path} -k 10
> python3 -m pecos.xmc.xtransformer.predict -t ${Tt_path} -m ${model_dir} -o ${Emb_path}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should be sth like pecos.xmc.xtransformer.encode?

Comment thread pecos/xmc/xtransformer/README.md Outdated

### Advanced Usage: Train/Pred params via json input
`pecos.xmc.xtransformer` supports accepting training and predicting parameters from an inpyt JSON file.
Moreover, `python3 -m pecos.xmc.xtransformer.trai` helpfully provide the option to generate all parameters in JSON format to stdout.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

the .trai is typo?

Comment thread pecos/xmc/xtransformer/README.md Outdated
```

### Python Example
This toy example demonstrates how to train and predict with PECOS X(R)-Transformer module using Python API.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

XR-Transformer


model_dir (str, optional): the i-th trained matcher will be saved to 'model_dir/{i}.model'
ranker_level (int, optional): number of ranker levels. Default 1 to use a single layer ranker
preliminary_indexer_params (HierarchicalKMeans.TrainParams): params to generate preliminary hierarchial label tree.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Update paper citation in line 43?

@OctoberChang
OctoberChang self-requested a review October 4, 2021 14:22
@jiong-zhang
jiong-zhang merged commit a6829f3 into amzn:mainline Oct 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants