tomaarsen HF Staff commited on
Commit
2a62d2b
·
verified ·
1 Parent(s): 009e600

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +118 -4
README.md CHANGED
@@ -1,10 +1,124 @@
1
  ---
2
  title: README
3
- emoji: 😻
4
- colorFrom: yellow
5
- colorTo: indigo
6
  sdk: static
7
  pinned: false
8
  ---
 
9
 
10
- Edit this `README.md` markdown file to author your organization card.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  title: README
3
+ emoji: ❤️
4
+ colorFrom: red
5
+ colorTo: red
6
  sdk: static
7
  pinned: false
8
  ---
9
+ SentenceTransformers 🤗 is a Python framework for state-of-the-art sentence, text and image embeddings.
10
 
11
+ Install the [Sentence Transformers](https://www.sbert.net/) library.
12
+ ```
13
+ pip install -U sentence-transformers
14
+ ```
15
+
16
+ The usage is as simple as:
17
+ ```python
18
+ from sentence_transformers import CrossEncoder
19
+
20
+ # Load a pre-trained CrossEncoder model
21
+ model = CrossEncoder("cross-encoder/ms-marco-MiniLM-L-6-v2")
22
+
23
+ # Predict scores for a pair of sentences
24
+ scores = model.predict([
25
+ ("How many people live in Berlin?", "Berlin had a population of 3,520,031 registered inhabitants in an area of 891.82 square kilometers."),
26
+ ("How many people live in Berlin?", "Berlin is well known for its museums."),
27
+ ])
28
+ # => array([ 8.607138 , -4.3200774], dtype=float32)
29
+ ```
30
+
31
+ Alternatively, you can also use the `CrossEncoder.rank` argument to rerank documents given a query:
32
+ ```python
33
+ from sentence_transformers import CrossEncoder
34
+
35
+ # Load a pre-trained CrossEncoder model
36
+ model = CrossEncoder("cross-encoder/ms-marco-MiniLM-L-6-v2")
37
+
38
+ # Rank a list of passages for a query
39
+ query = "How many people live in Berlin?"
40
+ passages = [
41
+ "Berlin had a population of 3,520,031 registered inhabitants in an area of 891.82 square kilometers.",
42
+ "Berlin is well known for its museums.",
43
+ "In 2014, the city state Berlin had 37,368 live births (+6.6%), a record number since 1991.",
44
+ "The urban area of Berlin comprised about 4.1 million people in 2014, making it the seventh most populous urban area in the European Union.",
45
+ "The city of Paris had a population of 2,165,423 people within its administrative city limits as of January 1, 2019",
46
+ "An estimated 300,000-420,000 Muslims reside in Berlin, making up about 8-11 percent of the population.",
47
+ "Berlin is subdivided into 12 boroughs or districts (Bezirke).",
48
+ "In 2015, the total labour force in Berlin was 1.85 million.",
49
+ "In 2013 around 600,000 Berliners were registered in one of the more than 2,300 sport and fitness clubs.",
50
+ "Berlin has a yearly total of about 135 million day visitors, which puts it in third place among the most-visited city destinations in the European Union.",
51
+ ]
52
+ ranks = model.rank(query, passages)
53
+
54
+ # Print the scores
55
+ print("Query:", query)
56
+ for rank in ranks:
57
+ print(f"{rank['score']:.2f}\t{passages[rank['corpus_id']]}")
58
+ """
59
+ Query: How many people live in Berlin?
60
+ 8.92 The urban area of Berlin comprised about 4.1 million people in 2014, making it the seventh most populous urban area in the European Union.
61
+ 8.61 Berlin had a population of 3,520,031 registered inhabitants in an area of 891.82 square kilometers.
62
+ 8.24 An estimated 300,000-420,000 Muslims reside in Berlin, making up about 8-11 percent of the population.
63
+ 7.60 In 2014, the city state Berlin had 37,368 live births (+6.6%), a record number since 1991.
64
+ 6.35 In 2013 around 600,000 Berliners were registered in one of the more than 2,300 sport and fitness clubs.
65
+ 5.42 Berlin has a yearly total of about 135 million day visitors, which puts it in third place among the most-visited city destinations in the European Union.
66
+ 3.45 In 2015, the total labour force in Berlin was 1.85 million.
67
+ 0.33 Berlin is subdivided into 12 boroughs or districts (Bezirke).
68
+ -4.24 The city of Paris had a population of 2,165,423 people within its administrative city limits as of January 1, 2019
69
+ -4.32 Berlin is well known for its museums.
70
+ """
71
+ ```
72
+
73
+ Hugging Face makes it easy to collaboratively build and showcase your [Sentence Transformers](https://www.sbert.net/) models! You can collaborate with your organization, upload and showcase your own models in your profile ❤️
74
+
75
+ <div class="grid lg:grid-cols-2 gap-x-4 gap-y-7">
76
+ <a href="https://www.sbert.net/" class="block overflow-hidden group">
77
+ <div
78
+ class="w-full h-40 object-cover mb-2 rounded-lg flex items-center justify-center bg-[#FA8072]"
79
+ >
80
+ <img alt="" src="https://huggingface.co/spaces/sentence-transformers/README/resolve/main/sbertLogo.png" class="w-40" />
81
+ </div>
82
+ <div class="underline">Documentation</div>
83
+ </a>
84
+ <a
85
+ href="https://sbert.net/docs/package_reference/cross_encoder/cross_encoder.html#sentence_transformers.cross_encoder.CrossEncoder.push_to_hub"
86
+ class="block overflow-hidden group"
87
+ >
88
+ <div
89
+ class="w-full h-40 mb-2 bg-gray-900 group-hover:bg-gray-850 rounded-lg flex items-start justify-start overflow-hidden"
90
+ >
91
+ <img
92
+ alt=""
93
+ src="https://huggingface.co/spaces/sentence-transformers/README/resolve/main/push-to-hub.png"
94
+ class="w-full h-40 object-cover overflow-hidden"
95
+ />
96
+ </div>
97
+ <div class="underline">Push your CrossEncoder models to the Hub ❤️ </div>
98
+ </a>
99
+ <!-- <a
100
+ href="https://huggingface.co/models?library=sentence-transformers&sort=downloads"
101
+ class="block overflow-hidden group"
102
+ >
103
+ <div
104
+ class="w-full h-40 mb-2 bg-gray-900 group-hover:bg-gray-850 rounded-lg flex items-start justify-start overflow-hidden"
105
+ >
106
+ <img
107
+ alt=""
108
+ src="https://huggingface.co/spaces/sentence-transformers/README/resolve/main/sbert-hf.png"
109
+ class="w-full h-40 object-cover overflow-hidden"
110
+ />
111
+ </div>
112
+ <div class="underline">Find all Sentence Transformers models on the 🤗 Hub</div>
113
+ </a> -->
114
+ </div>
115
+
116
+ To upload your CrossEncoder models to the Hugging Face Hub, log in with `huggingface-cli login` and use the [`push_to_hub`](https://sbert.net/docs/package_reference/cross_encoder/cross_encoder.html#sentence_transformers.cross_encoder.CrossEncoder.push_to_hub) method within the Sentence Transformers library.
117
+ ```python
118
+ from sentence_transformers import CrossEncoder
119
+
120
+ # Load or train a model
121
+ model = CrossEncoder(...)
122
+ # Push to Hub
123
+ model.push_to_hub("my_new_model")
124
+ ```