Trial2Vec
Wang, Zifeng and Sun, Jimeng. (2022). Trial2Vec: Zero-Shot Clinical Trial Document Similarity Search using Self-Supervision. Findings of EMNLP'22.
News
- 12/8/2022: Support
download_embeddingthat obtains the pretrained embedding only. It saves a lot of GPU/CPU memory! Please refer this example for detailed use cases.
from trial2vec import download_embedding
t2v_emb = download_embedding()
- 10/27/2022: Support
word_vectorandsentence_vector!
# sentence vectors
inputs = ['I am a sentence', 'I am another sentence']
outputs = model.sentence_vector(inputs)
# torch.tensor w/ shape [2, 128]
# word vectors
inputs = ['I am a sentence', 'I am another sentence abcdefg xyz']
outputs = model.word_vector(inputs)
# {'word_embs': torch.tensor w/ shape [2, max_token, 128], 'mask': torch.tensor w/ shape [2, max_token]}
Usage
Get pretrained Trial2Vec model in three lines:
from trial2vec import Trial2Vec
model = Trial2Vec()
model.from_pretrained()
A jupyter example is shown at https://github.com/RyanWangZf/Trial2Vec/blob/main/example/demo_trial2vec.ipynb.
How to install
Install the correct PyTorch version by referring to https://pytorch.org/get-started/locally/.
Then install Trial2Vec by
# Recommended because it is update to date, small bugs will be kept fixed
pip install git+https://github.com/RyanWangZf/Trial2Vec.git
or
pip install trial2vec
Search similar trials
Use Trial2Vec to search similar clinical trials:
# load demo data
from trial2vec import load_demo_data
data = load_demo_data()
# contains trial documents
test_data = {'x': data['x']}
# make prediction
pred = model.predict(test_data)
Encode trials
Use Trial2Vec to encode clinical trial documents:
test_data = {'x': df} # contains trial documents
emb = model.encode(test_data) # make inference
# or just find the pre-encoded trial documents
emb = [model[nct_id] for test_data['x']['nct_id']]
Continue training
One can continue to train the pretrained models on new trials as
# just formulate trial documents as the format of `data`
data = load_demo_data()
model.fit(
{
'x':data['x'], # document dataframe
'fields':data['fields'], # attribute field columns
'ctx_fields':data['ctx_fields'], # context field columns
'tag': data['tag'], # nct_id is the unique tag for each trial
},
valid_data={
'x':data['x_val'],
'y':data['y_val']
},
)
# save
model.save_model('./finetuned-trial2vec')
Metadata
Release files for Trial2Vec 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| Trial2Vec-0.1.0.tar.gz | 24.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| Trial2Vec-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 52.3 kB
Release files / Trial2Vec-0.1.0.tar.gz
| Download URL | Trial2Vec-0.1.0.tar.gz |
|---|---|
| Size | 24.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c1341bd852c598a6a02aefa43e38f3e3f80a17299469da7c9c57174979b927e3
|
|
BLAKE2b-256 checksum How to use checksums |
d8773917d553ab6d02b09d8f415977e8f124e8e89b4c6062184fb8bbbead56e6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.7.15
|
Release files / Trial2Vec-0.1.0-py3-none-any.whl
| Download URL | Trial2Vec-0.1.0-py3-none-any.whl |
|---|---|
| Size | 28.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
361c88f5a2fc7e74a5bcafceb409b109ce0ddce615721d412d960e684009a815
|
|
BLAKE2b-256 checksum How to use checksums |
0a0d15db1ee739865367d5bf4ea02426becaa489cb0188ffb33606db5fcdb9de
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.7.15
|
Security for Trial2Vec 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.