Trouble Saving a Hugging Face Dimensionality Reduced Model and Converting in ONNX for Use in NodeJS

Hi,

I have done/need to do the following:

  1. Generated word embeddings using sentence transformer (all-MiniLM-L6-v2):
#Model for which we apply dimensionality reduction
model = SentenceTransformer('all-MiniLM-L6-v2')
#New size for the embeddings
new_dimension = 128
######## Reduce the embedding dimensions ########
pca_train_sentences = ls
train_embeddings = model.encode(pca_train_sentences, convert_to_numpy=True)
#Compute PCA on the train embeddings matrix
pca = PCA(n_components=new_dimension)
pca.fit(train_embeddings)
pca_comp = np.asarray(pca.components_)

# We add a dense layer to the model, so that it will produce directly embeddings with the new size
dense = models.Dense(in_features=model.get_sentence_embedding_dimension(), out_features=new_dimension, bias=False, activation_function=torch.nn.Identity())
dense.linear.weight = torch.nn.Parameter(torch.tensor(pca_comp))
model.add_module('dense', dense)
model.save('models/my-128dim-model-local')
  1. Performed Dimensionality Reduced to get vector length of 128 instead of 384, followed XenovaTransformers(A NodeJS Implementation)
  2. I had to use this model from within Node JS, found the implementation (Xenova Transformers)
import { env } from '@xenova/transformers';
env.localModelPath = 'local/';
env.allowRemoteModels = false;
import { pipeline } from '@xenova/transformers';
const extractor = await pipeline('feature-extraction', 'my-128dim-model');
const sentences = ['This is an example sentence', 'Each sentence is converted'];
const output = await extractor(sentences, { pooling: 'mean', normalize: true });
console.log(output);
  1. I needed to convert my dimensionality reduced model to onnx as briefed so I can it in above, so I followed the in instruction here: ConvertToOnnx. Ran the following script:
    python -m scripts.convert --quantize --model_id ../my-128dim-model --task feature-extraction

This works but I am not getting a 128 dim vector but 384 still. What am I doing wrong?
Although when I try to convert a pretrained model from hugging face lib it works perfectly.

I will really appreciate your help because its been days and I am unable to solve the issue