Skip to content

Commit 177b053

Browse files
author
pfeatherstone
committed
- softmax is possibly a bit better
- readme
1 parent 118b45b commit 177b053

2 files changed

Lines changed: 27 additions & 10 deletions

File tree

‎README.md‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,25 @@
1+
![Ubuntu](https://github.com/pfeatherstone/hubert.cpp/actions/workflows/ubuntu.yml/badge.svg)
2+
13
# hubert.cpp
2-
C++ implementation of DistilHuBERT
4+
5+
C++ implementation of [DistilHuBERT](https://arxiv.org/pdf/2110.01900) using [Eigen](https://gitlab.com/libeigen/eigen).
6+
7+
## Example
8+
9+
```cpp
10+
hubert::model net;
11+
12+
float audio[16000]; // 16kHz mono audio
13+
std::span<const float> feats = net.encode(audio); // [T,768] : an array of 768 packed normalized features
14+
```
15+
16+
## Features
17+
18+
- [x] Dynamic sizes (but no batches)
19+
- [x] Weights compiled into the library
20+
- [x] Block-based API
21+
- [ ] Streaming API.
22+
23+
## Usage
24+
25+
- Useful for downstream tasks such as speech representation, speaker identification, classification, etc.

‎src/lib/hubert.cpp‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,6 @@ namespace hubert
278278
return x;
279279
}
280280

281-
template <class Derived>
282-
auto softmax(const Eigen::ArrayBase<Derived>& x)
283-
{
284-
const float m = x.maxCoeff();
285-
const auto e = (x - m).exp().eval();
286-
return (e / e.sum()).eval();
287-
}
288-
289281
//----------------------------------------------------------------------------------------------------------------
290282

291283
struct pos_embedding
@@ -373,7 +365,9 @@ namespace hubert
373365
for (size_t t{0}; t < T; ++t)
374366
{
375367
auto row = scores.row(t).array();
376-
row = softmax(row);
368+
const float m = row.maxCoeff();
369+
row = (row - m).exp();
370+
row /= row.sum();
377371
}
378372

379373
Oh.noalias() = scores * Vh;

0 commit comments

Comments
 (0)