Skip to main content

French NLP Toolkit

State of the art toolkit for Natural Language Processing in French based on CamemBERT/FlauBERT.

Citation:

@misc{hadoop,
  author={Wang Xiaoou},
  title={frenchnlp: state of the art toolkit for Natural Language Processing in French based on CamemBERT/FlauBERT},
  year={2021},
  howpublished={\url{https://github.com/xiaoouwang/frenchnlp}},
}
Wang Xiaoou. (2021). frenchnlp: state of the art toolkit for Natural Language Processing in French based on CamemBERT/FlauBERT. https://github.com/xiaoouwang/frenchnlp.
  • sentence similarity measure

    • For why average pooling/[cls] shouldn't be used to represent sentence, see

    Reimers, Nils, and Iryna Gurevych. “Sentence-BERT: Sentence Embeddings Using Siamese BERT-Networks.” ArXiv:1908.10084 [Cs], August 27, 2019. http://arxiv.org/abs/1908.10084.

    • For use of sentence similarity in real life, see

    Xiaoou Wang, Xingyu Liu, Yimei Yue. “Mesure de similarité textuelle pour l’évaluation automatique de copies d’étudiants.” TALN-RECITAL 2021. Download

  • to do, text classification pipelines

How to use the package

from frenchnlp import *
from transformers import AutoTokenizer, AutoModel
import torch

Transformer-based sentence similarity measure (using CamemBERT as example)

Using the [cls] token

compare_compare_cls(model,tokenizer,sentence1,sentence2)

fr_tokenizer = AutoTokenizer.from_pretrained('camembert-base')
fr_model = AutoModel.from_pretrained('camembert-base')

sentences = [
    "J'aime les chats.",
    "Je déteste les chats.",
    "J'adore les chats."
]

for i in range(1,3):
    print(f"similarité sémantique entre\n{sentences[0]}\n{sentences[i]}")
    print(bert_compare_cls(fr_model,fr_tokenizer,sentences[0],sentences[i]))

Output:

similarité sémantique entre
J'aime les chats.
Je déteste les chats.
0.9145417
similarité sémantique entre
J'aime les chats.
J'adore les chats.
0.9809468

Average pooling

compare_bert_average(model,tokenizer,sent1,sent2)

fr_tokenizer = AutoTokenizer.from_pretrained('camembert-base')
fr_model = AutoModel.from_pretrained('camembert-base')

for i in range(1,3):
    print(f"similarité sémantique entre\n{sentences[0]}\n{sentences[i]}")
    print(compare_bert_average(fr_model,fr_tokenizer,sentences[0],sentences[i])

Output:

similarité sémantique entre
J'aime les chats.
Je déteste les chats.
0.9145417
similarité sémantique entre
J'aime les chats.
J'adore les chats.
0.9809468

Using multilingual sentence embeddings

See above for the reference on multilingual sentence embeddings.

compare_sent_transformer(model,sent1,sent2)

from sentence_transformers import SentenceTransformer

sent_model = SentenceTransformer('stsb-xlm-r-multilingual')

for i in range(1,3):
    print(f"similarité sémantique entre\n{sentences[0]}\n{sentences[i]}")
    print(compare_sent_transformer(sent_model,sentences[0],sentences[i])

Output:

similarité sémantique entre
J'aime les chats.
Je déteste les chats.
0.46124768
similarité sémantique entre
J'aime les chats.
J'adore les chats.
0.9557947

License

Codes

frenchnlp is licensed under Apache License 2.0. You can use frenchnlp in your commercial products for free. We would appreciate it if you add a link to frenchnlp on your website.

Models

Unless otherwise specified, all models in frenchnlp are licensed under CC BY-NC-SA 4.0.

Metadata

Release files for frenchnlp 0.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for frenchnlp 0.2.3
File Size Uploaded Provenance
frenchnlp-0.2.3.tar.gz 7.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for frenchnlp 0.2.3
File Interpreter ABI Platform
frenchnlp-0.2.3-py3-none-any.whl Python 3 none any Details

Total release size: 52.0 kB

Release files / frenchnlp-0.2.3.tar.gz

Download URL frenchnlp-0.2.3.tar.gz
Size 7.0 kB
Tags Source
SHA-256 checksum
How to use checksums
2e1440e9edaa749e5ab564d19d56e2090acb77b31945a5d04b6e77c9d4b19010
BLAKE2b-256 checksum
How to use checksums
33db4bc5e1c3e0774d1e49a1d24b9682635ec856b77460eb5f7205dba01d62ab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.6

Release files / frenchnlp-0.2.3-py3-none-any.whl

Download URL frenchnlp-0.2.3-py3-none-any.whl
Size 45.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8037b9474891c4c85e3f6e3b3f52d34800f9451d96b16c4662c3bafda12f34b3
BLAKE2b-256 checksum
How to use checksums
ebe137d41ee08216af8240755505a5d54522cf930788d859fa87e6e8f904d2db
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.6

Security for frenchnlp 0.2.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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page