Skip to content

Commit

Permalink
Merge pull request #2369 from tomaarsen/docs/CLIP_from_scratch
Browse files Browse the repository at this point in the history
[`doc`] Add section about loading a CLIP model from scratch
  • Loading branch information
tomaarsen authored Dec 12, 2023
2 parents 5da2188 + 6b9755c commit 9b9438c
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions docs/training/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ The depicted architecture, consisting of a BERT layer and a pooling layer is one

## Creating Networks from Scratch

In the quick start & usage examples, we used pre-trained SentenceTransformer models that already come with a BERT layer and a pooling layer.
But we can create the networks architectures from scratch by defining the individual layers. For example, the following code would create the depicted network architecture:
In the quick start & usage examples, we used pre-trained SentenceTransformer models that already come with a BERT layer and a pooling layer.

But we can create the networks architectures from scratch by defining the individual layers. For example, the following code would create the depicted network architecture:

```python
from sentence_transformers import SentenceTransformer, models

Expand All @@ -50,6 +50,15 @@ model = SentenceTransformer(modules=[word_embedding_model, pooling_model, dense_

Here, we add on top of the pooling layer a fully connected dense layer with Tanh activation, which performs a down-project to 256 dimensions. Hence, embeddings by this model will only have 256 instead of 768 dimensions.

Additionally, we can also create SentenceTransformer models from scratch for image search by loading any CLIP model from the Hugging Face Hub or a local path:

```py
from sentence_transformers import SentenceTransformer, models

image_embedding_model = models.CLIPModel('openai/clip-vit-base-patch32')
model = SentenceTransformer(modules=[image_embedding_model])
```

For all available building blocks see [» Models Package Reference](../package_reference/models.md)

## Training Data
Expand Down

0 comments on commit 9b9438c

Please sign in to comment.