Skip to content

Commit a12eb42

Browse files
Merge pull request #83 from StabRise/81-add-transformer-for-compute-embedding
81 add transformer for compute embedding
2 parents 581ec8e + b5c9933 commit a12eb42

16 files changed

Lines changed: 572 additions & 9 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## [unreleased]
2+
3+
### 🚀 Features
4+
5+
- Added TextEmbeddings transformer, for compute embedding using SentenceTransformers
6+
7+
18
## [0.2.5] - 10.11.2025
29

310
### 🚀 Features

docs/source/embeddings.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Embeddings
2+
==========
3+
4+
## Overview
5+
6+
This section provides an overview of the various embedding transformers available in ScaleDP for processing text and other data types. These transformers are designed to generate embeddings that can be used for tasks such as clustering, classification, and semantic similarity.
7+
8+
## Text Embeddings
9+
10+
* [**TextEmbeddings**](models/embeddings/TextEmbeddings.md)
11+
12+
## Base Embeddings
13+
14+
* [**BaseEmbeddings**](models/embeddings/BaseEmbeddings.md)

docs/source/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Benefits of using ScaleDP
4646
pdf_processing.md
4747
detectors.md
4848
ocr.md
49+
embeddings.md
4950
show_utils.md
5051
release_notes.md
5152

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
(BaseEmbeddings)=
2+
# BaseEmbeddings
3+
4+
## Overview
5+
6+
`BaseEmbeddings` is an abstract base class for embedding transformers in ScaleDP. It provides the foundational structure and common functionality for embedding models, enabling efficient and scalable embedding generation for various data types. Derived classes, such as `TextEmbeddings`, extend this base class to implement specific embedding logic.
7+
8+
## Key Features
9+
10+
- **Abstract Base Class**: Provides a common interface for embedding transformers.
11+
- **PySpark Integration**: Designed to work seamlessly with PySpark for distributed data processing.
12+
- **Customizable Parameters**: Supports a wide range of parameters for flexibility and customization.
13+
- **Error Handling**: Includes validation for input columns and error propagation options.
14+
15+
## Usage Example
16+
17+
`BaseEmbeddings` is not intended to be used directly. Instead, it serves as a parent class for specific embedding transformers like `TextEmbeddings`.
18+
19+
## Parameters
20+
21+
| Parameter | Type | Description | Default |
22+
|-------------------|---------|--------------------------------------------------|-----------------------------|
23+
| inputCol | str | Input column name | N/A |
24+
| outputCol | str | Output column name | N/A |
25+
| keepInputData | bool | Whether to retain input data in the output | True |
26+
| device | Device | Device for computation (CPU/GPU) | Device.CPU |
27+
| model | str | Pre-trained model identifier | N/A |
28+
| batchSize | int | Batch size for processing | 1 |
29+
| numPartitions | int | Number of partitions for distributed processing | 1 |
30+
| partitionMap | bool | Use partitioned mapping | False |
31+
| pageCol | str | Page column | "page" |
32+
| pathCol | str | Path column | "path" |
33+
34+
## Notes
35+
36+
- `BaseEmbeddings` provides the `_transform` method, which handles the core logic for applying transformations to a dataset.
37+
- Derived classes must implement the `transform_udf` and `transform_udf_pandas` methods to define the specific embedding logic.
38+
- The class includes validation for input columns to ensure compatibility with the dataset.
39+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
(TextEmbeddings)=
2+
# TextEmbeddings
3+
4+
## Overview
5+
6+
`TextEmbeddings` is a text embedding transformer based on the SentenceTransformer model. It is designed to efficiently generate embeddings for text data using a pre-trained model. The transformer is implemented as a PySpark ML transformer and can be integrated into Spark pipelines for scalable text embedding tasks.
7+
8+
## Usage Example
9+
10+
```python
11+
from scaledp import TextEmbeddings, PipelineModel
12+
13+
text_embeddings = TextEmbeddings(
14+
inputCol="text",
15+
outputCol="embeddings",
16+
keepInputData=True,
17+
model="all-MiniLM-L6-v2",
18+
batchSize=1,
19+
device="cpu",
20+
)
21+
22+
# Transform the text dataframe through the embedding stage
23+
pipeline = PipelineModel(stages=[text_embeddings])
24+
result = pipeline.transform(text_df)
25+
result.show()
26+
```
27+
28+
## Parameters
29+
30+
| Parameter | Type | Description | Default |
31+
|-------------------|---------|--------------------------------------------------|-----------------------------|
32+
| inputCol | str | Input text column | "text" |
33+
| outputCol | str | Output column for embeddings | "embeddings" |
34+
| keepInputData | bool | Keep input data in output | True |
35+
| model | str | Pre-trained model identifier | "all-MiniLM-L6-v2" |
36+
| batchSize | int | Batch size for inference | 1 |
37+
| device | Device | Inference device (CPU/GPU) | Device.CPU |
38+
| numPartitions | int | Number of partitions | 1 |
39+
| partitionMap | bool | Use partitioned mapping | False |
40+
| pageCol | str | Page column | "page" |
41+
| pathCol | str | Path column | "path" |
42+
43+
## Notes
44+
- The transformer uses the SentenceTransformer model for generating text embeddings.
45+
- Supports batch processing and distributed inference with Spark.
46+
- Additional parameters can be set using the corresponding setter methods.

docs/source/release_notes.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,41 @@ Release Notes
44
This document outlines the release notes for the ScaledP project. It includes information about new features, bug fixes, and other changes made in each version.
55

66

7+
## [unreleased]
8+
9+
### 🚀 Features
10+
11+
- Added [TextEmbeddings](#TextEmbeddings) transformer, for compute embedding using SentenceTransformers
12+
13+
14+
## [0.2.5] - 10.11.2025
15+
16+
### 🚀 Features
17+
18+
- Added param 'returnEmpty' to [ImageCropBoxes](#ImageCropBoxes) for avoid to have exceptions if no boxes are found
19+
- Added labels param to the [YoloOnnxDetector](#YoloOnnxDetector)
20+
- Improve displaying labels in [ImageDrawBoxes](#ImageDrawBoxes)
21+
22+
### 🧰 Maintenance
23+
- Updated versions of dependencies (Pandas, Numpy, OpenCV)
24+
25+
### 🐛 Bug Fixes
26+
27+
- Fixed convert color schema in [YoloOnnxDetector](#YoloOnnxDetector)
28+
- Fixed show utils on Google Colab
29+
- Fixed imports of the DataFrame
30+
31+
### 📘 Jupyter Notebooks
32+
33+
- [YoloOnnxDetector.ipynb](https://github.com/StabRise/ScaleDP-Tutorials/blob/master/object-detection/1.YoloOnnxDetector.ipynb)
34+
- [FaceDetection.ipynb](https://github.com/StabRise/ScaleDP-Tutorials/blob/master/object-detection/2.FaceDetection.ipynb)
35+
- [SignatureDetection.ipynb](https://github.com/StabRise/ScaleDP-Tutorials/blob/master/object-detection/3.SignatureDetection.ipynb)
36+
37+
### 📝 Blog Posts
38+
39+
- [Running YOLO Models on Spark Using ScaleDP](https://stabrise.com/blog/running_yolo_on_spark_with_scaledp/)
40+
41+
742
## 0.2.4 - 02.11.2025
843

944
### 🚀 Features

0 commit comments

Comments
 (0)