File size: 4,673 Bytes
106ce68
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0291a66
106ce68
 
 
 
0291a66
 
 
 
 
106ce68
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
---
license: apache-2.0
library_name: sentence-transformers
pipeline_tag: sentence-similarity
base_model: nomic-ai/CodeRankEmbed
tags:
- verilog
- systemverilog
- code-search
- embeddings
---

# verilog-embed-base

`verilog-embed-base` is a text embedding model for finding Verilog and SystemVerilog modules from a natural-language description. It is `nomic-ai/CodeRankEmbed` fine-tuned on comment-module pairs taken from permissively licensed GitHub repositories. Silicon Model Factory, an agent-operated project by roboco-io, trained and evaluated it.

## Usage

The model uses the custom architecture code of its base model, so `trust_remote_code=True` is required. That code looks for a `pytorch_model.bin` file unless it is told to read safetensors, so pass `model_kwargs={"safe_serialization": True}`. Add the query prefix to search queries only, not to code.

```python
from sentence_transformers import SentenceTransformer

model = SentenceTransformer(
    "roboco-io/verilog-embed-base",
    trust_remote_code=True,
    model_kwargs={"safe_serialization": True},
)
model.max_seq_length = 512
prefix = "Represent this query for searching relevant code: "
queries = model.encode([prefix + "synchronous FIFO with configurable depth"], normalize_embeddings=True)
modules = model.encode(["module fifo #(parameter DEPTH = 16) (...); ... endmodule"], normalize_embeddings=True)
print(queries @ modules.T)
```

## Training data

The training set has 8,482 pairs. Each pair is the comment written directly above a `module` declaration and the module code. The pairs come from these sources:

- GitHub Verilog/SystemVerilog repositories (MIT)
- GitHub Verilog/SystemVerilog repositories (Apache-2.0)
- GitHub Verilog/SystemVerilog repositories (BSD-3-Clause)
- GitHub Verilog/SystemVerilog repositories (BSD-2-Clause)
- GitHub Verilog/SystemVerilog repositories (CC0-1.0)

The repositories were found with the GitHub search API (language Verilog or SystemVerilog, at least 10 stars, not a fork, not archived, one of the licenses above). `data-sources.json` in this repository lists every repository with its license, commit and split. Files with other license text, vendor copyright notices, generated code, or private markers were excluded. Testbench modules, duplicate modules, and duplicate descriptions were removed. Repositories were split by owner, so no owner appears in more than one split. No LLM-generated descriptions were used.

Training used `CachedMultipleNegativesRankingLoss` with a batch size of 64, 3 epochs, a learning rate of 2e-5, and a maximum input length of 512 tokens. It ran on one Tesla T4 for 396 steps. The checkpoint was selected with the dev split only.

## Evaluation

The test set is `verilog-comment-module-heldout-v1`: 1,642 held-out pairs from repository owners that do not appear in training. The query is the comment, and the corpus is all modules in the test set. Each query has one relevant module. The acceptance criterion was committed before training: the model must exceed the baseline `nomic-ai/CodeRankEmbed` (512 tokens) by at least 0.04 nDCG@10. Both models were measured on 2026-11-27 on the same GPU with the same script. The 95% intervals come from 1,000 bootstrap resamples of the queries.

| Model | nDCG@10 | 95% interval | MRR@10 | Recall@1 | Recall@10 |
|---|---|---|---|---|---|
| verilog-embed-base | 0.7492 | 0.7307-0.7651 | 0.7068 | 0.6102 | 0.8800 |
| nomic-ai/CodeRankEmbed | 0.6920 | 0.6726-0.7098 | 0.6464 | 0.5512 | 0.8350 |

The difference in nDCG@10 is +0.0572. Result against the acceptance criterion: passed (required at least 0.04).

## Limitations

The descriptions are comments that the original authors wrote above their modules. Real search queries can be shorter, vaguer, or written in other languages, and the model was not measured on such queries. The test set has one relevant module per query, so a module that matches the query equally well but is not the labelled one counts as a miss. The duplicate filter compares module code and names; renamed copies of the same module across repositories can remain and may raise the scores. The license filter is based on repository license files and keyword matches in each file; it can miss files whose license differs from the repository license. The model was not evaluated on code-to-code retrieval or on other hardware description languages such as VHDL or Chisel.

## License

This model is released under the Apache-2.0 license. The base model `nomic-ai/CodeRankEmbed` is under the MIT license. The training data comes from repositories under the MIT, Apache-2.0, BSD-3-Clause, BSD-2-Clause, and CC0-1.0 licenses, listed in `data-sources.json`.