news-deja-vu
Python package for News Deja Vu
News Deja Vu is a novel semantic search tool that leverages transformer large language models and a bi-encoder approach to identify historical news articles that share semantic similarities with modern news queries. News Déjà Vu first recognizes and masks entities, in order to focus on broader parallels rather than the specific named entities being discussed. Then, a contrastively trained, lightweight bi-encoder retrieves historical articles that are most similar semantically to a modern query.
Example Usage:
ner_model = 'bert-base-NER'
same_story_model = 'dell-research-harvard/same-story'
# Download historic news articles
corpus = download('american stories:1840')
# Perform NER inference
ner_output = ner_and_mask(corpus, ner_model, batch_size = batch_size)
# Embed with biencoder
embeddings = embed(ner_output, same_story_model)
# NER inference for query sentences
query_masked_input = ner_and_mask(sample_query_sentences, ner_model, batch_size = batch_size)
# Embed query sentences
query_embeddings = embed(query_masked_input, same_story_model)
# Search for closest matches in historical corpus
dist_list, nn_list = find_nearest_neighbours(query_embeddings, embeddings, k=1)
# Output results
results_dict = {i: {"query": sample_query_sentences[i], "neighbor": dataset[nn_list[i]]} for i in range(len(sample_query_sentences))}
with open('data/test_data/query_results_1840.json', 'w') as f:
json.dump(results_dict, f, indent = 4, default=str)
Or, in much simpler form:
corpus = download('american stories:1840')
results = search_same_story(sample_query_sentences, corpus, ner_model, same_story_model, k = 1)
Outputs are query texts matched with their nearest matches in the historical corpus.
Metadata
Release files for newsdejavu 0.0.3
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 | Actions |
|---|---|---|---|---|
| newsdejavu-0.0.3.tar.gz | 15.4 kB | Without provenance | Details for newsdejavu-0.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| newsdejavu-0.0.3-py3-none-any.whl | Python 3 | none | any | Details for newsdejavu-0.0.3-py3-none-any.whl |
Total release size: 31.4 kB
Release files / newsdejavu-0.0.3.tar.gz
| Download URL | newsdejavu-0.0.3.tar.gz |
|---|---|
| Size | 15.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
521712c094eb6acefc09350a4844c67cb9e44fda89dfa9c2e85d62f5914c1100
|
|
BLAKE2b-256 checksum How to use checksums |
c8cc96822ca808086857f31c9756085f6eb2edb1fe2dd2070aa6865c1d3428e6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.64.1 CPython/3.8.10
|
Release files / newsdejavu-0.0.3-py3-none-any.whl
| Download URL | newsdejavu-0.0.3-py3-none-any.whl |
|---|---|
| Size | 16.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d48e47f2252322939a4cca573021beea5c2fb87debb962494f701211d7dcc374
|
|
BLAKE2b-256 checksum How to use checksums |
e051e7df208117da324272e2fa3bb8de742a159f31f5e7b8eb003145293c8fe2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.64.1 CPython/3.8.10
|
Security for newsdejavu 0.0.3
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.