Comments (7)
There is a function in gptcache that does this, too. I'm using that code in my HF transformers code, it's just a few lines.
https://gptcache.readthedocs.io/en/latest/_modules/gptcache/embedding/rwkv.html?highlight=rwkv#
from rwkv-lm.
@BlinkDL how would the implementation look like for a def embed(text: str) -> List[float]:
method in RWKV
class? Such a method would be very useful. I asked gpt-4 about it and this is what it wrote:
class RWKV(pl.LightningModule):
# (...)
def embed(self, text: str) -> List[float]:
args = self.args
input_ids = args.tokenizer.encode(text)
input_ids = torch.tensor(input_ids).unsqueeze(0).cuda()
with torch.no_grad():
x = self.emb(input_ids)
x_emb = x
if args.tiny_att_dim > 0:
for block in self.blocks:
x = block(x, x_emb)
else:
for block in self.blocks:
x = block(x)
x = self.ln_out(x)
x = x[:, -1, :].detach().cpu()
return x.squeeze().tolist()
from rwkv-lm.
Thanks :) from the README here:
Read the inference code in src/model.py and try using the final hidden state(.xx .aa .bb) as a faithful sentence embedding for other tasks. Probably you shall begin with .xx and .aa/.bb (.aa divided by .bb).
from rwkv-lm.
Can you explaim future? still don't get what they mean and which value should be use. xx or aa / bb?
from rwkv-lm.
@tiendung the hidden state has 5 tensors per block (att+ffn): xx aa bb pp xx
from rwkv-lm.
@ricardopinto any progress with this? I'm also interested in working with embeddings generated with RWKV but still don't have a clear understanding of how we can make it work to get embeddings like any of the models from sentence-transformers
from rwkv-lm.
I'm now doing this in HF transformers. 430m seems faithful on writing style, not content.
from rwkv-lm.
Related Issues (20)
- RWKV for Text to Speech use case HOT 2
- RWKV-5 World on colab HOT 1
- Truncation in Tokenizer? HOT 1
- Finetuning RWKV-5-World-1B5-v2 model HOT 1
- 能否提供huggingface 上的全部RWKV v5模型的微调参数? HOT 1
- Can RWKV-v4 handle summarization tasks? HOT 1
- fintune RWKV5-7B Missing key(s) in state_dict: HOT 1
- KeyError: "attribute 'weight' already exists" HOT 1
- Tokenizer for fine tuning RWKV-v5 world model HOT 1
- Does RWKV-4 music use the RWKV-v4 network architecture? HOT 1
- RWKV 5 supported vLLM?LMdeploy?TGI?Fastllm?FasterTransformer? HOT 1
- how to train For long context HOT 1
- How to understand `no` variable in cuda code? HOT 1
- Can RWKV beat Flash Attention? HOT 1
- How does the generation speed of RWKV-5/6 compare to that of mamba with the same number of parameters? HOT 1
- NCCL watchdog thread terminated with exception: CUDA error: an illegal memory access was encountered HOT 1
- Probable mistake in Eq. 16 in the preprint HOT 2
- Flash Attention HOT 2
- The /v1/embeddings interface of rwkv is inconsistent with the /v1/embeddings interface of openai. How should they be compatible?
- bug in new wkv6state_cuda
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rwkv-lm.