metadata
tags:
- sentence-transformers
- sentence-similarity
- feature-extraction
- dense
- generated_from_trainer
- dataset_size:4500
- loss:MatryoshkaLoss
- loss:MultipleNegativesRankingLoss
base_model: ibm-granite/granite-embedding-english-r2
widget:
- source_sentence: >-
You are tasked with creating a module in Elm to render an article
document. The module should include functions to render the body,
navigation, main content, titles, headings, subheadings, paragraphs, code
blocks, images, and references. You need to define the necessary types and
functions to achieve this.
sentences:
- '4605'
- >-
Context:
Answer: ```elm
module ArticleRenderer exposing (Rendered, renderDocument, body,
navigation, mainContent, title, heading, subheading, paragraph,
codeBlock, imageBlock, renderReference)
import Html exposing (Html, div, nav, main, h1, h2, h3, p, img, pre,
figure, a, span)
import Html.Attributes exposing (style, src, href, target, rel, hidden,
type_)
import Html.Styled.Attributes as Attributes exposing (css)
import Document exposing (Inline, FlatInline, Key, Text, Link,
Reference, Code, Image)
type alias Rendered msg =
Html msg
-- Navigation
navigation : Rendered msg
navigation =
Html.nav
[ css [ Css.marginBottom (rem 1) ]
]
[ navLink "Go back to overview" Route.Index
]
navLink : String -> Route -> Rendered msg
navLink text route =
viewLink
{ url = Route.toPath route
, text = [ Html.text text ]
, styles = [ Css.fontStyle Css.italic ]
}
-- Document rendering
renderDocument : Article -> Rendered msg
renderDocument article =
article.document
|> List.map renderBlock
|> document
renderBlock : Block -> Rendered msg
renderBlock block =
case block of
Title content ->
title content
Heading contents ->
heading contents
Subheading contents ->
subheading contents
Paragraph contents ->
paragraph [] contents
CodeBlock code ->
codeBlock code
ImageBlock image ->
imageBlock image
-- Landmarks
body : List (Rendered msg) -> Rendered msg
body content =
Html.div
[ css
[ Css.padding (rem 1)
, Css.maxWidth (rem 48)
, Css.margin Css.auto
]
]
content
mainContent : List (Rendered msg) -> Rendered msg
mainContent contents =
Html.main_ [] contents
-- Text
title : String -> Rendered msg
title text =
Html.h1
[ css
[ headingStyle
, Css.fontSize (rem 1.5)
]
]
[ Html.text text ]
heading : List (Inline Path) -> Rendered msg
heading contents =
Html.h2
[ css
[ headingStyle
, Css.fontSize (rem 1.25)
]
]
(List.map renderInline contents)
subheading : List (Inline Path) -> Rendered msg
subheading contents =
Html.h3
[ css
[ headingStyle
, Css.fontSize (rem 1.1)
]
]
(List.map renderInline contents)
paragraph : List Css.Style -> List (Inline Path) -> Rendered msg
paragraph styles content =
Html.p
[ css (paragraphStyle :: styles)
]
(List.map renderInline content)
codeBlock : Document.Code -> Rendered msg
codeBlock code =
Html.pre [ css [ codeBackgroundStyle, Css.padding (em 1) ] ]
[ Html.code [ css [ codeFontStyle ] ] [ Html.text code.src ] ]
imageBlock : Document.Image Path -> Rendered msg
imageBlock image =
Html.figure
[ css
[ Css.margin2 paragraphSpacing zero
, framedStyle
]
]
[ Html.a
[ Attributes.href <| Path.toAbsolute image.fallbackSource.source.src
, Attributes.target "_blank"
, Attributes.rel "noopener"
]
[ Html.img
[ Attributes.src (Path.toAbsolute image.fallbackSource.source.src)
, Attributes.alt image.alt
, Attributes.width image.fallbackSource.source.width
, Attributes.height image.fallbackSource.source.height
, css
[ Css.display Css.block
, Css.maxWidth (pct 100)
, Css.width (pct 100)
, Css.height Css.auto
]
]
]
, Html.figcaption
[ css
[ Css.boxSizing Css.borderBox
, Css.width (pct 100)
, Css.padding (rem 0.5)
]
]
[ Html.text image.caption ]
]
-- Text styles
headingStyle : Css.Style
headingStyle =
Css.batch
[ headingFontFamily
, Css.fontWeight Css.bold
, Css.margin zero
, Css.lineHeight (num 1.2)
]
paragraphStyle : Css.Style
paragraphStyle =
Css.batch
[ paragraphFontStyle
, Css.margin zero
]
codeFontStyle : Css.Style
codeFontStyle =
Css.batch
[ Css.whiteSpace Css.preWrap
, Css.fontFamilies [ "Source Code Pro", "monospace" ]
]
codeBackgroundStyle : Css.Style
codeBackgroundStyle =
Css.batch
[ Css.borderRadius (em 0.2)
, Css.backgroundColor (Css.hsla 0 0 0.5 0.15)
, Css.padding2 (em 0.05) (em 0.2)
, Css.fontSize (em 0.95)
]
framedStyle : Css.Style
framedStyle =
let
spacing =
0.5
in
Css.batch
[ framedBorderStyle
, Css.borderRadius (rem spacing)
]
framedBorderStyle : Css.Style
framedBorderStyle =
Css.border3 (px 1) Css.solid borderColor
paragraphSpacing : Css.Rem
paragraphSpacing =
rem 1
borderColor : Css.Color
borderColor =
Css.hsla 0 0 0 0.25
paragraphFontStyle : Css.Style
paragraphFontStyle =
Css.batch
[ Css.lineHeight (num 1.35)
]
-- Helper functions
renderInline : Inline Path -> Rendered msg
renderInline inline =
case inline of
TextInline text ->
renderText [] text
LinkInline link ->
renderLink link
ReferenceInline reference ->
renderReference reference
CodeInline code ->
renderCode code
KeysInline keys ->
renderKeys keys
renderText : List Css.Style -> Text -> Rendered msg
renderText extraStyles text =
let
italic =
if text.style.emphasized then
[ Css.fontStyle Css.italic ]
else
[]
styles =
italic ++ extraStyles
in
if text.style.emphasized then
Html.em [ css styles ] [ Html.text text.content ]
else if List.isEmpty styles then
Html.text text.content
else
Html.span [ css styles ] [ Html.text text.content ]
renderLink : Link -> Rendered msg
renderLink link =
viewLink
{ text = List.map (renderText []) link.text
, url = Url.toString link.url
, styles = []
}
viewLink : { text : List (Rendered msg), url : String, styles : List
Css.Style } -> Rendered msg
viewLink { text, url, styles } =
let
unvisitedColor =
Css.rgb 22 22 162
visitedColor =
Css.inherit
in
Html.a
[ Attributes.href url
, css
([ Css.color unvisitedColor
, Css.visited
[ Css.color visitedColor
]
, hover
[ Css.textDecorationStyle Css.dotted
]
]
++ styles
)
]
text
renderReference : Reference Path -> Rendered msg
renderReference reference =
viewLink
{ text =
List.map
(renderText
[ Css.fontWeight Css.bold
, Css.fontSize (em 0.8)
]
)
reference.text
, url = Path.toAbsolute reference.path
, styles = []
}
renderCode : Code -> Rendered msg
renderCode code =
Html.code
[ css [ codeFontStyle, codeBackgroundStyle ]
]
[ Html.text code.src ]
renderKeys : Keys -> Rendered msg
renderKeys keys =
case keys of
( first, [] ) ->
renderKey first
( first, rest ) ->
Html.kbd [ css [ Css.whiteSpace Css.preWrap ] ]
(List.map renderKey (first :: rest)
|> List.intersperse (Html.text "+\u{200B}")
)
renderKey : Key -> Rendered msg
renderKey key =
let
keyBorderColor =
Css.hsl 0 0 0.75
keyText =
case key of
Letter l ->
String.fromChar l
Ctrl ->
"Ctrl"
Shift ->
"Shift\u{00A0}⇧"
Enter ->
"Enter\u{00A0}↵"
Tab ->
"Tab\u{00A0}↹"
Up ->
"↑\u{00A0}up"
Down ->
"↓\u{00A0}down"
in
Html.kbd
[ css
[ codeFontStyle
, Css.fontSize (em 0.8)
, Css.padding2 (em 0) (em 0.1)
, Css.border3 (px 1) Css.solid keyBorderColor
, Css.borderRadius (em 0.2)
, Css.boxShadow5 Css.inset zero (px -1) zero keyBorderColor
, Css.verticalAlign Css.center
, Css.whiteSpace Css.pre
]
]
[ Html.text keyText ]
```
- |-
Context:
Answer: 40
- source_sentence: >-
You are tasked with creating a graded object in a category `C` using a
type `β`. A graded object over `C` is essentially a function `β → C` into
the objects of `C`. Your goal is to define the `graded_object` in a
category, where you will project the `i`-th component of the graded object
and create a shift functor on the graded objects. Additionally, you need
to construct the total functor `graded_object β C ⥤ C` and prove that it
is faithful.
Write a program that accomplishes the following tasks:
1. Define the graded object in a category.
2. Create a shift functor on the graded objects.
3. Construct the total functor and prove that it is faithful.
sentences:
- |-
Context:
Answer: 33
- '1514'
- >-
Context:
Answer: ```haskell
import algebra.group.basic
import category_theory.pi.basic
import category_theory.shift
namespace category_theory
universes w v u
def graded_object (β : Type w) (C : Type u) : Type (max w u) := β → C
instance inhabited_graded_object (β : Type w) (C : Type u) [inhabited C]
:
inhabited (graded_object β C) :=
⟨λ b, inhabited.default C⟩
instance category_of_graded_objects (β : Type w) : category.{(max w v)}
(graded_object β C) :=
category_theory.pi (λ _, C)
def eval {β : Type w} (b : β) : graded_object β C ⥤ C :=
{ obj := λ X, X b,
map := λ X Y f, f b }
section
variable (C)
def comap_eq {β γ : Type w} {f g : β → γ} (h : f = g) : comap (λ _, C) f
≅ comap (λ _, C) g :=
{ hom := { app := λ X b, eq_to_hom begin dsimp [comap], subst h, end },
inv := { app := λ X b, eq_to_hom begin dsimp [comap], subst h, end }, }
lemma comap_eq_symm {β γ : Type w} {f g : β → γ} (h : f = g) :
comap_eq C h.symm = (comap_eq C h).symm :=
by tidy
lemma comap_eq_trans {β γ : Type w} {f g h : β → γ} (k : f = g) (l : g =
h) :
comap_eq C (k.trans l) = comap_eq C k ≪≫ comap_eq C l :=
begin
ext X b,
simp,
end
def comap_equiv {β γ : Type w} (e : β ≃ γ) :
(graded_object β C) ≌ (graded_object γ C) :=
{ functor := comap (λ _, C) (e.symm : γ → β),
inverse := comap (λ _, C) (e : β → γ),
counit_iso := (comap_comp (λ _, C) _ _).trans (comap_eq C (by { ext, simp } )),
unit_iso := (comap_eq C (by { ext, simp } )).trans (comap_comp _ _ _).symm,
functor_unit_iso_comp' := λ X, by { ext b, dsimp, simp, } }
end
instance has_shift {β : Type*} [add_comm_group β] (s : β) :
has_shift (graded_object_with_shift s C) :=
{ shift := comap_equiv C
{ to_fun := λ b, b-s,
inv_fun := λ b, b+s,
left_inv := λ x, (by simp),
right_inv := λ x, (by simp), } }
instance has_zero_morphisms [has_zero_morphisms C] (β : Type w) :
has_zero_morphisms.{(max w v)} (graded_object β C) :=
{ has_zero := λ X Y,
{ zero := λ b, 0 } }
lemma zero_apply [has_zero_morphisms C] (β : Type w) (X Y :
graded_object β C) (b : β) :
(0 : X ⟶ Y) b = 0 := rfl
open_locale zero_object
instance has_zero_object [has_zero_object C] [has_zero_morphisms C] (β :
Type w) :
has_zero_object.{(max w v)} (graded_object β C) :=
{ zero := λ b, (0 : C),
unique_to := λ X, ⟨⟨λ b, 0⟩, λ f, (by ext)⟩,
unique_from := λ X, ⟨⟨λ b, 0⟩, λ f, (by ext)⟩, } }
variables (β : Type)
variables (C : Type u) [category.{v} C]
variables [has_coproducts C]
def total : graded_object β C ⥤ C :=
{ obj := λ X, ∐ (λ i : ulift.{v} β, X i.down),
map := λ X Y f, limits.sigma.map (λ i, f i.down) }
instance : faithful (total β C) :=
{ map_injective' := λ X Y f g w,
begin
classical,
ext i,
replace w := sigma.ι (λ i : ulift.{v} β, X i.down) ⟨i⟩ ≫= w,
erw [colimit.ι_map, colimit.ι_map] at w,
exact mono.right_cancellation _ _ w,
end }
end graded_object
```
- source_sentence: >-
You are required to implement a CUDA kernel function for deterministic
devoxelization. The function takes input features of size (n, c), indices
of size (N, 8), weight of size (N, 8), and is expected to produce output
features of size (N, c). The kernel function should be able to perform the
following steps:
1. Calculate the index based on the thread and block dimensions.
2. Iterate through each value of i (less than N) and j (less than c).
3. Access the corresponding indices, weight, and feat based on the current
iteration.
4. Perform a calculation involving the indices, weight, and feat arrays to
populate the output array.
sentences:
- |-
Context:
Answer: -15
- >-
Context:
Answer: ```c
#include <stdio.h>
#include <stdlib.h>
#include <thrust/device_vector.h>
#include "../common/gpu.cuh"
__global__ void deterministic_devoxelize_kernel(int N, int c, const int
*__restrict__ indices, const float *__restrict__ weight, const float
*__restrict__ feat, float *__restrict__ out){
int index = blockIdx.x * blockDim.x + threadIdx.x;
int i = index / c;
int j = index % c;
if(i < N){
const int* indices_ = indices + 8 * i;
const float *weight_ = weight + 8 * i;
const float *feat_ = feat + j;
float cur_feat;
for(int k = 0; k < 8; k++){
cur_feat = (indices_[k] >= 0) ? feat_[indices_[k] * c] : 0;
out[i * c + j] += weight_[k] * cur_feat;
}
}
}
void deterministic_devoxelize_wrapper(int N, int c, const int * indices,
const float * weight, const float * feat, float * out){
deterministic_devoxelize_kernel<<<N, c>>>(N, c, indices, weight, feat, out);
}
```
Please note that the solution provided is a CUDA kernel function for
deterministic devoxelization, along with a wrapper function for easier
usage.
- '4073'
- source_sentence: >-
You are tasked with implementing a grayscale morphological operation with
flat linear structuring elements in C++ using the CUDA framework. Your
function should take in an input volume, step vectors for line segments,
the number of steps for line segments, an operation to perform, and the
block size for GPU processing. The input volume is a numeric array, the
lineSteps parameter is an int32 matrix representing step vectors for line
segments, and the lineLens parameter is an int32 vector representing the
number of steps for line segments.
Your function should validate the inputs and ensure that the number of
steps vectors and step lengths are equal. It should then allocate an
output volume and extract line segments from the input parameters.
Finally, your function should perform the specified morphological
operation using flat linear structuring elements and return the output
volume with the result of the operation.
sentences:
- '3896'
- >-
Context:
Answer: SMTP is a push protocol for sending emails, while IMAP (Internet
Message Access Protocol) is a pull protocol for retrieving emails from a
server. IMAP allows users to manage emails on the server (e.g.,
filtering, searching), whereas SMTP only transmits messages. IMAP is
preferred for client access because it enables asynchronous retrieval,
supports offline use, and maintains email state across devices, unlike
SMTP's stateless nature.
- >-
Context:
Answer: ```cpp
#include <stdexcept>
#include <vector>
#include "mex.h"
#include "view.cuh"
#include "morph.cuh"
#include "strel.cuh"
#include "flat_linear_morph.cuh"
#include "mex_common.cuh"
template <class Ty>
void flatLinearMorphOp(mxArray *mxRes, const mxArray *mxVol, const
std::vector<gpho::LineSeg>& lines,
int op, int3 blockSize);
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray
*prhs[])
{
// Validate inputs (to be implemented)
// Allocate output (to be implemented)
// Extract line segments (to be implemented)
// Run function (to be implemented)
}
template <class Ty>
void flatLinearMorphOp(mxArray *mxRes, const mxArray *mxVol, const
std::vector<gpho::LineSeg>& lines,
int op, int3 blockSize)
{
gpho::HostView<Ty> res(static_cast<Ty *>(mxGetData(mxRes)), volSize(mxRes));
gpho::HostView<const Ty> vol(static_cast<const Ty *>(mxGetData(mxVol)), volSize(mxVol));
switch (op) {
case MOP_DILATE:
gpho::flatLinearDilateErode<gpho::MORPH_DILATE>(res, vol, lines, blockSize);
break;
case MOP_ERODE:
gpho::flatLinearDilateErode<gpho::MORPH_ERODE>(res, vol, lines, blockSize);
break;
default:
abortWithMsg("invalid morphology op");
}
}
```
- source_sentence: Calculate $(-1)^{47} + 2^{(3^3+4^2-6^2)}$.
sentences:
- |-
Context:
Answer: 2
- |-
Context:
Answer: 127
- '4750'
pipeline_tag: sentence-similarity
library_name: sentence-transformers
metrics:
- cosine_accuracy@1
- cosine_accuracy@3
- cosine_accuracy@5
- cosine_accuracy@10
- cosine_precision@1
- cosine_precision@3
- cosine_precision@5
- cosine_precision@10
- cosine_recall@1
- cosine_recall@3
- cosine_recall@5
- cosine_recall@10
- cosine_ndcg@10
- cosine_mrr@10
- cosine_map@100
model-index:
- name: SentenceTransformer based on ibm-granite/granite-embedding-english-r2
results:
- task:
type: information-retrieval
name: Information Retrieval
dataset:
name: dim 768
type: dim_768
metrics:
- type: cosine_accuracy@1
value: 0.626
name: Cosine Accuracy@1
- type: cosine_accuracy@3
value: 0.706
name: Cosine Accuracy@3
- type: cosine_accuracy@5
value: 0.726
name: Cosine Accuracy@5
- type: cosine_accuracy@10
value: 0.758
name: Cosine Accuracy@10
- type: cosine_precision@1
value: 0.626
name: Cosine Precision@1
- type: cosine_precision@3
value: 0.23533333333333334
name: Cosine Precision@3
- type: cosine_precision@5
value: 0.1452
name: Cosine Precision@5
- type: cosine_precision@10
value: 0.07579999999999998
name: Cosine Precision@10
- type: cosine_recall@1
value: 0.626
name: Cosine Recall@1
- type: cosine_recall@3
value: 0.706
name: Cosine Recall@3
- type: cosine_recall@5
value: 0.726
name: Cosine Recall@5
- type: cosine_recall@10
value: 0.758
name: Cosine Recall@10
- type: cosine_ndcg@10
value: 0.6916401386587206
name: Cosine Ndcg@10
- type: cosine_mrr@10
value: 0.6704460317460319
name: Cosine Mrr@10
- type: cosine_map@100
value: 0.6750546261347222
name: Cosine Map@100
- task:
type: information-retrieval
name: Information Retrieval
dataset:
name: dim 512
type: dim_512
metrics:
- type: cosine_accuracy@1
value: 0.636
name: Cosine Accuracy@1
- type: cosine_accuracy@3
value: 0.7
name: Cosine Accuracy@3
- type: cosine_accuracy@5
value: 0.724
name: Cosine Accuracy@5
- type: cosine_accuracy@10
value: 0.758
name: Cosine Accuracy@10
- type: cosine_precision@1
value: 0.636
name: Cosine Precision@1
- type: cosine_precision@3
value: 0.23333333333333334
name: Cosine Precision@3
- type: cosine_precision@5
value: 0.1448
name: Cosine Precision@5
- type: cosine_precision@10
value: 0.07579999999999998
name: Cosine Precision@10
- type: cosine_recall@1
value: 0.636
name: Cosine Recall@1
- type: cosine_recall@3
value: 0.7
name: Cosine Recall@3
- type: cosine_recall@5
value: 0.724
name: Cosine Recall@5
- type: cosine_recall@10
value: 0.758
name: Cosine Recall@10
- type: cosine_ndcg@10
value: 0.694038077949631
name: Cosine Ndcg@10
- type: cosine_mrr@10
value: 0.6738849206349207
name: Cosine Mrr@10
- type: cosine_map@100
value: 0.6784599411787897
name: Cosine Map@100
- task:
type: information-retrieval
name: Information Retrieval
dataset:
name: dim 256
type: dim_256
metrics:
- type: cosine_accuracy@1
value: 0.638
name: Cosine Accuracy@1
- type: cosine_accuracy@3
value: 0.698
name: Cosine Accuracy@3
- type: cosine_accuracy@5
value: 0.712
name: Cosine Accuracy@5
- type: cosine_accuracy@10
value: 0.75
name: Cosine Accuracy@10
- type: cosine_precision@1
value: 0.638
name: Cosine Precision@1
- type: cosine_precision@3
value: 0.2326666666666667
name: Cosine Precision@3
- type: cosine_precision@5
value: 0.14239999999999997
name: Cosine Precision@5
- type: cosine_precision@10
value: 0.075
name: Cosine Precision@10
- type: cosine_recall@1
value: 0.638
name: Cosine Recall@1
- type: cosine_recall@3
value: 0.698
name: Cosine Recall@3
- type: cosine_recall@5
value: 0.712
name: Cosine Recall@5
- type: cosine_recall@10
value: 0.75
name: Cosine Recall@10
- type: cosine_ndcg@10
value: 0.6915490012428582
name: Cosine Ndcg@10
- type: cosine_mrr@10
value: 0.6731365079365079
name: Cosine Mrr@10
- type: cosine_map@100
value: 0.6780550682950801
name: Cosine Map@100
- task:
type: information-retrieval
name: Information Retrieval
dataset:
name: dim 128
type: dim_128
metrics:
- type: cosine_accuracy@1
value: 0.636
name: Cosine Accuracy@1
- type: cosine_accuracy@3
value: 0.698
name: Cosine Accuracy@3
- type: cosine_accuracy@5
value: 0.716
name: Cosine Accuracy@5
- type: cosine_accuracy@10
value: 0.74
name: Cosine Accuracy@10
- type: cosine_precision@1
value: 0.636
name: Cosine Precision@1
- type: cosine_precision@3
value: 0.23266666666666666
name: Cosine Precision@3
- type: cosine_precision@5
value: 0.1432
name: Cosine Precision@5
- type: cosine_precision@10
value: 0.074
name: Cosine Precision@10
- type: cosine_recall@1
value: 0.636
name: Cosine Recall@1
- type: cosine_recall@3
value: 0.698
name: Cosine Recall@3
- type: cosine_recall@5
value: 0.716
name: Cosine Recall@5
- type: cosine_recall@10
value: 0.74
name: Cosine Recall@10
- type: cosine_ndcg@10
value: 0.6863050743630661
name: Cosine Ndcg@10
- type: cosine_mrr@10
value: 0.6692539682539683
name: Cosine Mrr@10
- type: cosine_map@100
value: 0.6739281987227784
name: Cosine Map@100
- task:
type: information-retrieval
name: Information Retrieval
dataset:
name: dim 64
type: dim_64
metrics:
- type: cosine_accuracy@1
value: 0.628
name: Cosine Accuracy@1
- type: cosine_accuracy@3
value: 0.692
name: Cosine Accuracy@3
- type: cosine_accuracy@5
value: 0.714
name: Cosine Accuracy@5
- type: cosine_accuracy@10
value: 0.734
name: Cosine Accuracy@10
- type: cosine_precision@1
value: 0.628
name: Cosine Precision@1
- type: cosine_precision@3
value: 0.23066666666666666
name: Cosine Precision@3
- type: cosine_precision@5
value: 0.14279999999999998
name: Cosine Precision@5
- type: cosine_precision@10
value: 0.0734
name: Cosine Precision@10
- type: cosine_recall@1
value: 0.628
name: Cosine Recall@1
- type: cosine_recall@3
value: 0.692
name: Cosine Recall@3
- type: cosine_recall@5
value: 0.714
name: Cosine Recall@5
- type: cosine_recall@10
value: 0.734
name: Cosine Recall@10
- type: cosine_ndcg@10
value: 0.680595460049486
name: Cosine Ndcg@10
- type: cosine_mrr@10
value: 0.6635103174603174
name: Cosine Mrr@10
- type: cosine_map@100
value: 0.6681288217342812
name: Cosine Map@100
SentenceTransformer based on ibm-granite/granite-embedding-english-r2
This is a sentence-transformers model finetuned from ibm-granite/granite-embedding-english-r2. It maps sentences & paragraphs to a 768-dimensional dense vector space and can be used for semantic textual similarity, semantic search, paraphrase mining, text classification, clustering, and more.
Model Details
Model Description
- Model Type: Sentence Transformer
- Base model: ibm-granite/granite-embedding-english-r2
- Maximum Sequence Length: 512 tokens
- Output Dimensionality: 768 dimensions
- Similarity Function: Cosine Similarity
Model Sources
- Documentation: Sentence Transformers Documentation
- Repository: Sentence Transformers on GitHub
- Hugging Face: Sentence Transformers on Hugging Face
Full Model Architecture
SentenceTransformer(
(0): Transformer({'max_seq_length': 512, 'do_lower_case': False, 'architecture': 'ModernBertModel'})
(1): Pooling({'word_embedding_dimension': 768, 'pooling_mode_cls_token': True, 'pooling_mode_mean_tokens': False, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False, 'pooling_mode_weightedmean_tokens': False, 'pooling_mode_lasttoken': False, 'include_prompt': True})
)
Usage
Direct Usage (Sentence Transformers)
First install the Sentence Transformers library:
pip install -U sentence-transformers
Then you can load this model and run inference.
from sentence_transformers import SentenceTransformer
# Download from the 🤗 Hub
model = SentenceTransformer("shatonix/granite-embedding-math-cs")
# Run inference
sentences = [
'Calculate $(-1)^{47} + 2^{(3^3+4^2-6^2)}$.',
'Context: \nAnswer: 127',
'4750',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 768]
# Get the similarity scores for the embeddings
similarities = model.similarity(embeddings, embeddings)
print(similarities)
# tensor([[ 1.0000, 0.5650, -0.0154],
# [ 0.5650, 1.0000, -0.0246],
# [-0.0154, -0.0246, 1.0000]])
Evaluation
Metrics
Information Retrieval
- Dataset:
dim_768 - Evaluated with
InformationRetrievalEvaluatorwith these parameters:{ "truncate_dim": 768 }
| Metric | Value |
|---|---|
| cosine_accuracy@1 | 0.626 |
| cosine_accuracy@3 | 0.706 |
| cosine_accuracy@5 | 0.726 |
| cosine_accuracy@10 | 0.758 |
| cosine_precision@1 | 0.626 |
| cosine_precision@3 | 0.2353 |
| cosine_precision@5 | 0.1452 |
| cosine_precision@10 | 0.0758 |
| cosine_recall@1 | 0.626 |
| cosine_recall@3 | 0.706 |
| cosine_recall@5 | 0.726 |
| cosine_recall@10 | 0.758 |
| cosine_ndcg@10 | 0.6916 |
| cosine_mrr@10 | 0.6704 |
| cosine_map@100 | 0.6751 |
Information Retrieval
- Dataset:
dim_512 - Evaluated with
InformationRetrievalEvaluatorwith these parameters:{ "truncate_dim": 512 }
| Metric | Value |
|---|---|
| cosine_accuracy@1 | 0.636 |
| cosine_accuracy@3 | 0.7 |
| cosine_accuracy@5 | 0.724 |
| cosine_accuracy@10 | 0.758 |
| cosine_precision@1 | 0.636 |
| cosine_precision@3 | 0.2333 |
| cosine_precision@5 | 0.1448 |
| cosine_precision@10 | 0.0758 |
| cosine_recall@1 | 0.636 |
| cosine_recall@3 | 0.7 |
| cosine_recall@5 | 0.724 |
| cosine_recall@10 | 0.758 |
| cosine_ndcg@10 | 0.694 |
| cosine_mrr@10 | 0.6739 |
| cosine_map@100 | 0.6785 |
Information Retrieval
- Dataset:
dim_256 - Evaluated with
InformationRetrievalEvaluatorwith these parameters:{ "truncate_dim": 256 }
| Metric | Value |
|---|---|
| cosine_accuracy@1 | 0.638 |
| cosine_accuracy@3 | 0.698 |
| cosine_accuracy@5 | 0.712 |
| cosine_accuracy@10 | 0.75 |
| cosine_precision@1 | 0.638 |
| cosine_precision@3 | 0.2327 |
| cosine_precision@5 | 0.1424 |
| cosine_precision@10 | 0.075 |
| cosine_recall@1 | 0.638 |
| cosine_recall@3 | 0.698 |
| cosine_recall@5 | 0.712 |
| cosine_recall@10 | 0.75 |
| cosine_ndcg@10 | 0.6915 |
| cosine_mrr@10 | 0.6731 |
| cosine_map@100 | 0.6781 |
Information Retrieval
- Dataset:
dim_128 - Evaluated with
InformationRetrievalEvaluatorwith these parameters:{ "truncate_dim": 128 }
| Metric | Value |
|---|---|
| cosine_accuracy@1 | 0.636 |
| cosine_accuracy@3 | 0.698 |
| cosine_accuracy@5 | 0.716 |
| cosine_accuracy@10 | 0.74 |
| cosine_precision@1 | 0.636 |
| cosine_precision@3 | 0.2327 |
| cosine_precision@5 | 0.1432 |
| cosine_precision@10 | 0.074 |
| cosine_recall@1 | 0.636 |
| cosine_recall@3 | 0.698 |
| cosine_recall@5 | 0.716 |
| cosine_recall@10 | 0.74 |
| cosine_ndcg@10 | 0.6863 |
| cosine_mrr@10 | 0.6693 |
| cosine_map@100 | 0.6739 |
Information Retrieval
- Dataset:
dim_64 - Evaluated with
InformationRetrievalEvaluatorwith these parameters:{ "truncate_dim": 64 }
| Metric | Value |
|---|---|
| cosine_accuracy@1 | 0.628 |
| cosine_accuracy@3 | 0.692 |
| cosine_accuracy@5 | 0.714 |
| cosine_accuracy@10 | 0.734 |
| cosine_precision@1 | 0.628 |
| cosine_precision@3 | 0.2307 |
| cosine_precision@5 | 0.1428 |
| cosine_precision@10 | 0.0734 |
| cosine_recall@1 | 0.628 |
| cosine_recall@3 | 0.692 |
| cosine_recall@5 | 0.714 |
| cosine_recall@10 | 0.734 |
| cosine_ndcg@10 | 0.6806 |
| cosine_mrr@10 | 0.6635 |
| cosine_map@100 | 0.6681 |
Training Details
Training Dataset
Unnamed Dataset
- Size: 4,500 training samples
- Columns:
anchor,positive, andid - Approximate statistics based on the first 1000 samples:
anchor positive id type string string string details - min: 8 tokens
- mean: 80.08 tokens
- max: 512 tokens
- min: 9 tokens
- mean: 165.53 tokens
- max: 512 tokens
- min: 3 tokens
- mean: 3.81 tokens
- max: 4 tokens
- Samples:
anchor positive id Stella’s antique shop has 3 dolls, 2 clocks and 5 glasses for sale. She sells the dolls for $5 each. The clocks are priced at $15 each. The glasses are priced at $4 each. If she spent $40 to buy everything and she sells all of her merchandise, how much profit will she make?Context:
Answer: 253430You are tasked with creating a Ruby program that defines a service for creating a project in a Continuous Integration (CI) system. The service should be able to execute with valid parameters and handle specific scenarios.
The program should include the following:
- A class calledCi::CreateProjectServicethat defines the service for creating a project.
- A method within theCi::CreateProjectServiceclass calledexecutethat takes in three parameters:current_user(representing the current user),project(representing the project to be created), andci_origin_project(optional, representing the project to use as a template for settings and jobs).
- Theexecutemethod should handle the following scenarios:
1. When executed with valid parameters, it should return a new instance ofCi::Projectthat is persisted.
2. When executed without a project dump (empty string), it should raise an exception.
3. When executed with aci_origin_projectfor forking, it should use ...Context:
Answer:ruby<br>class Ci::CreateProjectService<br> def execute(current_user, project, ci_origin_project = nil)<br> if project.empty?<br> raise StandardError, 'Project dump is required'<br> end<br><br> new_project = Ci::Project.new<br> new_project.save<br><br> if ci_origin_project<br> new_project.shared_runners_enabled = ci_origin_project.shared_runners_enabled<br> new_project.public = ci_origin_project.public<br> new_project.allow_git_fetch = ci_origin_project.allow_git_fetch<br> end<br><br> new_project<br> end<br>end<br>656Why is the Insertion Sort algorithm considered optimal for nearly sorted datasets, and how does its time complexity compare to other quadratic sorting algorithms?Context:
Answer: Insertion Sort operates in O(n²) time complexity in the worst case, but for nearly sorted datasets, it achieves O(n) time complexity. This is because it only requires a minimal number of swaps to place elements in order. For datasets where most elements are already in their correct positions, the number of inversions (pairs out of order) is small, reducing the number of comparisons and swaps. This contrasts with other quadratic algorithms like Selection Sort, which must scan the entire dataset for each element, leading to O(n²) operations regardless of initial order. The efficiency of Insertion Sort for nearly sorted data stems from its ability to leverage existing order, making it a better choice for such scenarios.1305 - Loss:
MatryoshkaLosswith these parameters:{ "loss": "MultipleNegativesRankingLoss", "matryoshka_dims": [ 768, 512, 256, 128, 64 ], "matryoshka_weights": [ 1, 1, 1, 1, 1 ], "n_dims_per_step": -1 }
Training Hyperparameters
Non-Default Hyperparameters
eval_strategy: epochper_device_train_batch_size: 64per_device_eval_batch_size: 64gradient_accumulation_steps: 2num_train_epochs: 10lr_scheduler_type: cosinewarmup_ratio: 0.1bf16: Truetf32: Truedataloader_num_workers: 4load_best_model_at_end: Truebatch_sampler: no_duplicates
All Hyperparameters
Click to expand
overwrite_output_dir: Falsedo_predict: Falseeval_strategy: epochprediction_loss_only: Trueper_device_train_batch_size: 64per_device_eval_batch_size: 64per_gpu_train_batch_size: Noneper_gpu_eval_batch_size: Nonegradient_accumulation_steps: 2eval_accumulation_steps: Nonetorch_empty_cache_steps: Nonelearning_rate: 5e-05weight_decay: 0.0adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08max_grad_norm: 1.0num_train_epochs: 10max_steps: -1lr_scheduler_type: cosinelr_scheduler_kwargs: {}warmup_ratio: 0.1warmup_steps: 0log_level: passivelog_level_replica: warninglog_on_each_node: Truelogging_nan_inf_filter: Truesave_safetensors: Truesave_on_each_node: Falsesave_only_model: Falserestore_callback_states_from_checkpoint: Falseno_cuda: Falseuse_cpu: Falseuse_mps_device: Falseseed: 42data_seed: Nonejit_mode_eval: Falsebf16: Truefp16: Falsefp16_opt_level: O1half_precision_backend: autobf16_full_eval: Falsefp16_full_eval: Falsetf32: Truelocal_rank: 0ddp_backend: Nonetpu_num_cores: Nonetpu_metrics_debug: Falsedebug: []dataloader_drop_last: Falsedataloader_num_workers: 4dataloader_prefetch_factor: Nonepast_index: -1disable_tqdm: Falseremove_unused_columns: Truelabel_names: Noneload_best_model_at_end: Trueignore_data_skip: Falsefsdp: []fsdp_min_num_params: 0fsdp_config: {'min_num_params': 0, 'xla': False, 'xla_fsdp_v2': False, 'xla_fsdp_grad_ckpt': False}fsdp_transformer_layer_cls_to_wrap: Noneaccelerator_config: {'split_batches': False, 'dispatch_batches': None, 'even_batches': True, 'use_seedable_sampler': True, 'non_blocking': False, 'gradient_accumulation_kwargs': None}parallelism_config: Nonedeepspeed: Nonelabel_smoothing_factor: 0.0optim: adamw_torch_fusedoptim_args: Noneadafactor: Falsegroup_by_length: Falselength_column_name: lengthproject: huggingfacetrackio_space_id: trackioddp_find_unused_parameters: Noneddp_bucket_cap_mb: Noneddp_broadcast_buffers: Falsedataloader_pin_memory: Truedataloader_persistent_workers: Falseskip_memory_metrics: Trueuse_legacy_prediction_loop: Falsepush_to_hub: Falseresume_from_checkpoint: Nonehub_model_id: Nonehub_strategy: every_savehub_private_repo: Nonehub_always_push: Falsehub_revision: Nonegradient_checkpointing: Falsegradient_checkpointing_kwargs: Noneinclude_inputs_for_metrics: Falseinclude_for_metrics: []eval_do_concat_batches: Truefp16_backend: autopush_to_hub_model_id: Nonepush_to_hub_organization: Nonemp_parameters:auto_find_batch_size: Falsefull_determinism: Falsetorchdynamo: Noneray_scope: lastddp_timeout: 1800torch_compile: Falsetorch_compile_backend: Nonetorch_compile_mode: Noneinclude_tokens_per_second: Falseinclude_num_input_tokens_seen: noneftune_noise_alpha: Noneoptim_target_modules: Nonebatch_eval_metrics: Falseeval_on_start: Falseuse_liger_kernel: Falseliger_kernel_config: Noneeval_use_gather_object: Falseaverage_tokens_across_devices: Trueprompts: Nonebatch_sampler: no_duplicatesmulti_dataset_batch_sampler: proportionalrouter_mapping: {}learning_rate_mapping: {}
Training Logs
| Epoch | Step | Training Loss | dim_768_cosine_ndcg@10 | dim_512_cosine_ndcg@10 | dim_256_cosine_ndcg@10 | dim_128_cosine_ndcg@10 | dim_64_cosine_ndcg@10 |
|---|---|---|---|---|---|---|---|
| -1 | -1 | - | 0.6227 | 0.6213 | 0.6163 | 0.6036 | 0.5905 |
| 0.2817 | 10 | 10.3671 | - | - | - | - | - |
| 0.5634 | 20 | 8.1302 | - | - | - | - | - |
| 0.8451 | 30 | 6.6781 | - | - | - | - | - |
| 1.0 | 36 | - | 0.6371 | 0.6373 | 0.6368 | 0.6384 | 0.6297 |
| 1.1127 | 40 | 5.6041 | - | - | - | - | - |
| 1.3944 | 50 | 5.3589 | - | - | - | - | - |
| 1.6761 | 60 | 5.2615 | - | - | - | - | - |
| 1.9577 | 70 | 5.1322 | - | - | - | - | - |
| 2.0 | 72 | - | 0.6584 | 0.6599 | 0.6567 | 0.6590 | 0.6588 |
| 2.2254 | 80 | 4.2222 | - | - | - | - | - |
| 2.5070 | 90 | 3.6282 | - | - | - | - | - |
| 2.7887 | 100 | 3.5652 | - | - | - | - | - |
| 3.0 | 108 | - | 0.6679 | 0.6724 | 0.6750 | 0.6699 | 0.6645 |
| 3.0563 | 110 | 3.1212 | - | - | - | - | - |
| 3.3380 | 120 | 1.8016 | - | - | - | - | - |
| 3.6197 | 130 | 1.8941 | - | - | - | - | - |
| 3.9014 | 140 | 1.8576 | - | - | - | - | - |
| 4.0 | 144 | - | 0.6900 | 0.6923 | 0.6937 | 0.6863 | 0.6771 |
| 4.1690 | 150 | 1.0872 | - | - | - | - | - |
| 4.4507 | 160 | 0.7482 | - | - | - | - | - |
| 4.7324 | 170 | 0.7307 | - | - | - | - | - |
| 5.0 | 180 | 0.8322 | 0.6909 | 0.6988 | 0.6947 | 0.6873 | 0.6800 |
| 5.2817 | 190 | 0.329 | - | - | - | - | - |
| 5.5634 | 200 | 0.3246 | - | - | - | - | - |
| 5.8451 | 210 | 0.274 | - | - | - | - | - |
| 6.0 | 216 | - | 0.6898 | 0.6929 | 0.6904 | 0.6900 | 0.6801 |
| 6.1127 | 220 | 0.2161 | - | - | - | - | - |
| 6.3944 | 230 | 0.1178 | - | - | - | - | - |
| 6.6761 | 240 | 0.1418 | - | - | - | - | - |
| 6.9577 | 250 | 0.1319 | - | - | - | - | - |
| 7.0 | 252 | - | 0.6920 | 0.6890 | 0.6910 | 0.6880 | 0.6789 |
| 7.2254 | 260 | 0.0979 | - | - | - | - | - |
| 7.5070 | 270 | 0.0653 | - | - | - | - | - |
| 7.7887 | 280 | 0.0852 | - | - | - | - | - |
| 8.0 | 288 | - | 0.6934 | 0.69 | 0.6934 | 0.6877 | 0.6825 |
| 8.0563 | 290 | 0.08 | - | - | - | - | - |
| 8.3380 | 300 | 0.0526 | - | - | - | - | - |
| 8.6197 | 310 | 0.066 | - | - | - | - | - |
| 8.9014 | 320 | 0.0549 | - | - | - | - | - |
| 9.0 | 324 | - | 0.6911 | 0.6929 | 0.6905 | 0.6858 | 0.6802 |
| 9.1690 | 330 | 0.0384 | - | - | - | - | - |
| 9.4507 | 340 | 0.0523 | - | - | - | - | - |
| 9.7324 | 350 | 0.0333 | - | - | - | - | - |
| 10.0 | 360 | 0.0488 | 0.6916 | 0.6940 | 0.6915 | 0.6863 | 0.6806 |
- The bold row denotes the saved checkpoint.
Framework Versions
- Python: 3.12.12
- Sentence Transformers: 5.2.0
- Transformers: 4.57.3
- PyTorch: 2.9.1+cu128
- Accelerate: 1.12.0
- Datasets: 4.4.2
- Tokenizers: 0.22.1
Citation
BibTeX
Sentence Transformers
@inproceedings{reimers-2019-sentence-bert,
title = "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks",
author = "Reimers, Nils and Gurevych, Iryna",
booktitle = "Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing",
month = "11",
year = "2019",
publisher = "Association for Computational Linguistics",
url = "https://arxiv.org/abs/1908.10084",
}
MatryoshkaLoss
@misc{kusupati2024matryoshka,
title={Matryoshka Representation Learning},
author={Aditya Kusupati and Gantavya Bhatt and Aniket Rege and Matthew Wallingford and Aditya Sinha and Vivek Ramanujan and William Howard-Snyder and Kaifeng Chen and Sham Kakade and Prateek Jain and Ali Farhadi},
year={2024},
eprint={2205.13147},
archivePrefix={arXiv},
primaryClass={cs.LG}
}
MultipleNegativesRankingLoss
@misc{henderson2017efficient,
title={Efficient Natural Language Response Suggestion for Smart Reply},
author={Matthew Henderson and Rami Al-Rfou and Brian Strope and Yun-hsuan Sung and Laszlo Lukacs and Ruiqi Guo and Sanjiv Kumar and Balint Miklos and Ray Kurzweil},
year={2017},
eprint={1705.00652},
archivePrefix={arXiv},
primaryClass={cs.CL}
}