Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

docs: fix typos etc #666

Merged
merged 11 commits into from
Jan 26, 2023
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Add efficientnet b7 as a new image to image search backbone. ([#662](https://github.com/jina-ai/finetuner/pull/662))

- Fix typos, duplicate paragraphs, and wrong formulations. ([#666](https://github.com/jina-ai/finetuner/pull/666))


## [0.7.0] - 2023-01-18

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ clustering, duplication detection, anomaly detection, or other uses.
📈 **Performance promise**: Enhance the performance of pre-trained models so that they deliver state-of-the-art performance on
domain-specific applications.

🔱 **Simple yet powerful**: Easy access to 40+ mainstream loss functions, 10+ optimisers, layer pruning, weight
🔱 **Simple yet powerful**: Easy access to 40+ mainstream loss functions, 10+ optimizers, layer pruning, weight
freezing, dimensionality reduction, hard-negative mining, cross-modal models, and distributed training.

☁ **All-in-cloud**: Train using our free GPU infrastructure, manage runs, experiments and artifacts on Jina AI Cloud
☁ **All-in-cloud**: Train using our free GPU infrastructure, manage runs, experiments, and artifacts on Jina AI Cloud
without worrying about resource availability, complex integration, or infrastructure costs.

<!-- end elevator-pitch -->
Expand Down
2 changes: 1 addition & 1 deletion docs/advanced-topics/linear-probe.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ run = finetuner.fit(

Finetuner will:

1. Remove the classification head of `ResNet` model, and convert it into an embedding model.
1. Remove the classification head of a `ResNet` model, and convert it into an embedding model.
2. Freeze all layers of the embedding model.
3. Attach a trainable 3-layer Linear Projection Head on top of the embedding model with an `output_dim=1024`.

Expand Down
22 changes: 11 additions & 11 deletions docs/advanced-topics/negative-mining.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

Negative Mining is an advanced machine learning technique, which optimizes the way data is sampled from your training dataset.
Usually, it aims at making the metric learning tasks for the model harder during the training.
In this way it can lead to better fine-tuning results.
In this way, it can lead to better fine-tuning results.

## Context: Deep Metric Learning

Expand All @@ -22,8 +22,8 @@ Finetuner will evenly sample *X* items per class to make a batch *B* which is en

Afterward, the loss is calculated based on the relations between the embeddings.
Many of Finetuner's loss functions contrast the embeddings of three items, or a __Triplet__.
Finetuner creates all possible Triplets *(anchor, pos, neg)* from this batch which satisfy the following conditions:
For each Triplet, the first is the __anchor__, the second is an embedding that ought to be closer to the embedding of the anchor (has the same label), and the third is one that should be further from the anchor (has a different label).
Finetuner creates all possible triplets *(anchor, pos, neg)* from this batch which satisfy the following conditions:
For each triplet, the first is the __anchor__, the second is an embedding that ought to be closer to the embedding of the anchor (has the same label), and the third is one that should be further from the anchor (has a different label).
The objective is to pull the embeddings of items that belong to the same class closer together in the embedding space,
while pushing the embeddings of items which belong to different classes farther away from each other.

Expand All @@ -32,12 +32,12 @@ while pushing the embeddings of items which belong to different classes farther

## The Triplet Margin Miner

For some Triplets, the pre-trained model already performs well, i.e.
For some triplets, the pre-trained model already performs well, i.e.

the distance between the `anchor` embedding and `pos` is much smaller than
the distance between `anchor` and `neg`?
These Triplets do not contribute to improving the model, since they are already in the desired relation to each other in the embedding space.
A more effective way is to use only a subset of all Triplets for model training. We call this subset the **hard** or **semi-hard negative samples**.
These triplets do not contribute to improving the model, since they are already in the desired relation to each other in the embedding space.
A more effective way is to use only a subset of all triplets for model training. We call this subset the **hard** or **semi-hard negative samples**.

![mining](../imgs/mining.png)

Expand All @@ -49,7 +49,7 @@ If:
+ `D(anchor, pos) < D(anchor, neg) < D(anchor, pos) + margin`, where `neg` is a little further from the `pos`, but within the margin, then `neg` can be considered as a "semi-hard negative" (`2₄ - S`).
+ `D(anchor, neg) > D(anchor, pos) + margin`, then `neg` can be considered as "easy negative" (`2₄ - E`).

Training is more effective when using only **hard** and **semi-hard** negatives, given a reasonable margin value to distinguish them from **easy** Triplets.
Training is more effective when using only **hard** and **semi-hard** negatives, given a reasonable margin value to distinguish them from **easy** triplets.

## Doing Negative Mining in Finetuner

Expand All @@ -61,7 +61,7 @@ For instance, if you choose to train a model with the `TripleMarginLoss`, you ca
While without this miner, all possible triples with an anchor, a positive, and a negative candidate are used to calculate the loss, the miner reduces this set of triples.
By default, the miner only selects triples with hard negatives where the distance between the positive and the negative example is inside a margin of `0.2`.
To pass additional parameters to configure the miner, use the `miner_options` parameter of the fit function.
For example, to use only hard-negative Triples and set the margin to `0.3`:
For example, add the following to use only hard-negative triplets and set the margin to `0.3`:

```diff
run = finetuner.fit(
Expand All @@ -84,6 +84,6 @@ For a detailed description of the miners and their parameters, see the [PyTorch

## Summary

Metric Learning and Triplets are extremely useful for fine-tuning models for similarity search.
Easy Triplets have little impact on improving the model.
Consider using semi-hard/hard Triplets for model tuning.
Metric Learning and triplets are extremely useful for fine-tuning models for similarity search.
Easy triplets have little impact on improving the model.
Consider using semi-hard/hard triplets for model tuning.
5 changes: 3 additions & 2 deletions docs/advanced-topics/using-callbacks.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,16 @@ We can not ensure it works for other types of models, such as ResNet or BERT.

Finetuner allows you to utilize Weights & Biases for experiment tracking and visualization.
The `WandBLogger` uses Weights & Biases [Anonymous Mode](https://docs.wandb.ai/ref/app/features/anon)
to track a Finetuner Run. The benefits of anonymous mode is: you do not need to share your
to track a Finetuner Run. The benefits of anonymous mode are: you do not need to share your

Weights & Biases api_key with us since no login is required.

```{admonition} Use WandBLogger together with EvaluationCallback
:class: hint
The WandBLogger will track the training loss, plus the evaluation loss if `eval_data` is not None.

If you use EvaluationCallback together with WandBLogger, search metrics will be tracked as well.
Such as `mrr`, `precision`, `recall` etc.
Such as `mrr`, `precision`, `recall`, etc.
```

```python
Expand Down
6 changes: 1 addition & 5 deletions docs/get-started/how-it-works.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@ This involves three steps:

## Step 1: Build an embedding model

Finetuner interprets the architecture of an existing (pre-trained model) which we call backbone.
Those model might not be an embedding model upfront and the architecture not suitable for training it to encode data into embeddings.
Therefore, Finetuner removes the default *head*, applies *pooling* and freezes layers that do not need to be trained.

Finetuner takes an existing, pre-trained model, typically called the __backbone__, and analyzes its architecture.
If this model does not already produce embeddings, Finetuner is able to remove the default *head* (the last layers of the network), add new projection layers, apply *pooling*, and freeze layers that do not need to be trained.
If this model does not already produce embeddings or the architecture is not suitable for training, Finetuner is able to remove the default *head* (the last layers of the network), add new projection layers, apply *pooling*, and freeze layers that do not need to be trained.

For instance, Finetuner will turn an image classification model, e.g., for separating cats from dogs, into an *embedding model*
by removing its last layer - the classification head (cat-dog classifier).
Expand Down
12 changes: 6 additions & 6 deletions docs/notebooks/image_to_image.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
"\n",
"<a href=\"https://colab.research.google.com/drive/1QuUTy3iVR-kTPljkwplKYaJ-NTCgPEc_?usp=sharing\"><img alt=\"Open In Colab\" src=\"https://colab.research.google.com/assets/colab-badge.svg\"></a>\n",
"\n",
"Searching visually similar images with image queries is a very popular use-case. However, using pre-trained models does not deliver the best results – the models are trained on general data that lack the particularities of your specific task. Here's where Finetuner comes in! It enables you to accomplish this easily.\n",
"Searching visually similar images with image queries is a very popular use case. However, using pre-trained models does not deliver the best results – the models are trained on general data that lack the particularities of your specific task. Here's where Finetuner comes in! It enables you to accomplish this easily.\n",
"\n",
"This guide will demonstrate how to fine-tune a ResNet model for image to image retrieval.\n",
"This guide will demonstrate how to fine-tune a ResNet model for image-to-image retrieval.\n",
"\n",
"*Note, please consider switching to GPU/TPU Runtime for faster inference.*\n",
"\n",
Expand Down Expand Up @@ -221,7 +221,7 @@
"source": [
"## Evaluating\n",
"Currently, we don't have a user-friendly way to get evaluation metrics from the `finetuner.callback.EvaluationCallback` we initialized previously.\n",
"What you can do for now is to call `run.logs()` in the end of the run and see evaluation results:\n",
"What you can do for now is to call `run.logs()` after the end of the run and see the evaluation results:\n",
"\n",
"```bash\n",
" Training [5/5] ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 76/76 0:00:00 0:03:15 • loss: 0.003\n",
Expand Down Expand Up @@ -306,7 +306,7 @@
{
"cell_type": "markdown",
"source": [
"And finally you can use the embeded `query` to find top-k visually related images within `index_data` as follows:"
"And finally, you can use the embedded `query` to find top-k visually related images within `index_data` as follows:"
],
"metadata": {
"id": "1cC46TQ9pw-H"
Expand All @@ -327,7 +327,7 @@
"cell_type": "markdown",
"source": [
"## Before and after\n",
"We can directly compare the results of our fine-tuned model with its zero-shot counterpart to get a better idea of how finetuning affects the results of a search. While the differences between the two models may be subtle for some queries, some of the examples the examples below (such as the second example) show that the model after fine-tuning is able to better match similar images."
"We can directly compare the results of our fine-tuned model with its zero-shot counterpart to get a better idea of how finetuning affects the results of a search. While the differences between the two models may be subtle for some queries, some of the examples below (such as the second example) show that the model after fine-tuning is able to better match similar images."
],
"metadata": {
"id": "irvn0igWdLOf"
Expand All @@ -340,7 +340,7 @@
"\n",
"![image-image-triplets-good](https://user-images.githubusercontent.com/6599259/212634591-03bd93dc-900f-47c5-8ada-77cf1d4f9fe6.png)\n",
"\n",
"On the other hand, there are also cases where the fine-tuned model performs worse, and fails to correctly match images that it previously could. This case is much rarer than the previous case. For this dataset there were 108 occasions where the fine-tuned model returned the correct pair where it couldn't before, and only 33 occasions where the finetuned model returned an incorrect image after fine-tuning but returned a correct one before. Nevertheless it still can happen:\n",
"On the other hand, there are also cases where the fine-tuned model performs worse, and fails to correctly match images that it previously could. This case is much rarer than the previous case. For this dataset, there were 108 occasions where the fine-tuned model returned the correct pair where it couldn't before and only 33 occasions where the finetuned model returned an incorrect image after fine-tuning but returned a correct one before. Nevertheless, it still can happen:\n",
"\n",
"![image-image-triplets-bad](https://user-images.githubusercontent.com/6599259/212634649-370b643b-63ad-4d46-8a16-bc4988265568.png)"
],
Expand Down
12 changes: 6 additions & 6 deletions docs/notebooks/image_to_image.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ jupyter:

<a href="https://colab.research.google.com/drive/1QuUTy3iVR-kTPljkwplKYaJ-NTCgPEc_?usp=sharing"><img alt="Open In Colab" src="https://colab.research.google.com/assets/colab-badge.svg"></a>

Searching visually similar images with image queries is a very popular use-case. However, using pre-trained models does not deliver the best results – the models are trained on general data that lack the particularities of your specific task. Here's where Finetuner comes in! It enables you to accomplish this easily.
Searching visually similar images with image queries is a very popular use case. However, using pre-trained models does not deliver the best results – the models are trained on general data that lack the particularities of your specific task. Here's where Finetuner comes in! It enables you to accomplish this easily.

This guide will demonstrate how to fine-tune a ResNet model for image to image retrieval.
This guide will demonstrate how to fine-tune a ResNet model for image-to-image retrieval.

*Note, please consider switching to GPU/TPU Runtime for faster inference.*

Expand Down Expand Up @@ -140,7 +140,7 @@ You can continue monitoring the runs by checking the status - `finetuner.run.Run
<!-- #region id="BMpQxydypeZ3" -->
## Evaluating
Currently, we don't have a user-friendly way to get evaluation metrics from the `finetuner.callback.EvaluationCallback` we initialized previously.
What you can do for now is to call `run.logs()` in the end of the run and see evaluation results:
What you can do for now is to call `run.logs()` after the end of the run and see the evaluation results:

```bash
Training [5/5] ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 76/76 0:00:00 0:03:15 • loss: 0.003
Expand Down Expand Up @@ -197,7 +197,7 @@ assert query.embeddings.shape == (1, 2048)
```

<!-- #region id="1cC46TQ9pw-H" -->
And finally you can use the embeded `query` to find top-k visually related images within `index_data` as follows:
And finally, you can use the embedded `query` to find top-k visually related images within `index_data` as follows:
<!-- #endregion -->

```python id="tBYG9OKrpZ36"
Expand All @@ -206,15 +206,15 @@ query.match(index_data, limit=10, metric='cosine')

<!-- #region id="irvn0igWdLOf" -->
## Before and after
We can directly compare the results of our fine-tuned model with its zero-shot counterpart to get a better idea of how finetuning affects the results of a search. While the differences between the two models may be subtle for some queries, some of the examples the examples below (such as the second example) show that the model after fine-tuning is able to better match similar images.
We can directly compare the results of our fine-tuned model with its zero-shot counterpart to get a better idea of how finetuning affects the results of a search. While the differences between the two models may be subtle for some queries, some of the examples below (such as the second example) show that the model after fine-tuning is able to better match similar images.
<!-- #endregion -->

<!-- #region id="TwL33Jz1datD" -->
To save you some time, we have plotted some examples where the model's ability to return similar images has clearly improved:

![image-image-triplets-good](https://user-images.githubusercontent.com/6599259/212634591-03bd93dc-900f-47c5-8ada-77cf1d4f9fe6.png)

On the other hand, there are also cases where the fine-tuned model performs worse, and fails to correctly match images that it previously could. This case is much rarer than the previous case. For this dataset there were 108 occasions where the fine-tuned model returned the correct pair where it couldn't before, and only 33 occasions where the finetuned model returned an incorrect image after fine-tuning but returned a correct one before. Nevertheless it still can happen:
On the other hand, there are also cases where the fine-tuned model performs worse, and fails to correctly match images that it previously could. This case is much rarer than the previous case. For this dataset, there were 108 occasions where the fine-tuned model returned the correct pair where it couldn't before and only 33 occasions where the finetuned model returned an incorrect image after fine-tuning but returned a correct one before. Nevertheless, it still can happen:

![image-image-triplets-bad](https://user-images.githubusercontent.com/6599259/212634649-370b643b-63ad-4d46-8a16-bc4988265568.png)
<!-- #endregion -->
Loading