Skip to content

Commit

Permalink
Fix typo "constrastive" (keras-team#1295)
Browse files Browse the repository at this point in the history
  • Loading branch information
jondo authored Apr 5, 2023
1 parent 143a57c commit 3d16268
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
16 changes: 8 additions & 8 deletions examples/vision/ipynb/siamese_contrastive.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"source": [
"epochs = 10\n",
"batch_size = 16\n",
"margin = 1 # Margin for constrastive loss."
"margin = 1 # Margin for contrastive loss."
]
},
{
Expand Down Expand Up @@ -506,7 +506,7 @@
"colab_type": "text"
},
"source": [
"## Define the constrastive Loss"
"## Define the contrastive Loss"
]
},
{
Expand All @@ -519,28 +519,28 @@
"source": [
"\n",
"def loss(margin=1):\n",
" \"\"\"Provides 'constrastive_loss' an enclosing scope with variable 'margin'.\n",
" \"\"\"Provides 'contrastive_loss' an enclosing scope with variable 'margin'.\n",
"\n",
" Arguments:\n",
" margin: Integer, defines the baseline for distance for which pairs\n",
" should be classified as dissimilar. - (default is 1).\n",
"\n",
" Returns:\n",
" 'constrastive_loss' function with data ('margin') attached.\n",
" 'contrastive_loss' function with data ('margin') attached.\n",
" \"\"\"\n",
"\n",
" # Contrastive loss = mean( (1-true_value) * square(prediction) +\n",
" # true_value * square( max(margin-prediction, 0) ))\n",
" def contrastive_loss(y_true, y_pred):\n",
" \"\"\"Calculates the constrastive loss.\n",
" \"\"\"Calculates the contrastive loss.\n",
"\n",
" Arguments:\n",
" y_true: List of labels, each label is of type float32.\n",
" y_pred: List of predictions of same length as of y_true,\n",
" each label is of type float32.\n",
"\n",
" Returns:\n",
" A tensor containing constrastive loss as floating point value.\n",
" A tensor containing contrastive loss as floating point value.\n",
" \"\"\"\n",
"\n",
" square_pred = tf.math.square(y_pred)\n",
Expand Down Expand Up @@ -644,8 +644,8 @@
"# Plot the accuracy\n",
"plt_metric(history=history.history, metric=\"accuracy\", title=\"Model accuracy\")\n",
"\n",
"# Plot the constrastive loss\n",
"plt_metric(history=history.history, metric=\"loss\", title=\"Constrastive Loss\")"
"# Plot the contrastive loss\n",
"plt_metric(history=history.history, metric=\"loss\", title=\"Contrastive Loss\")"
]
},
{
Expand Down
16 changes: 8 additions & 8 deletions examples/vision/md/siamese_contrastive.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import matplotlib.pyplot as plt
```python
epochs = 10
batch_size = 16
margin = 1 # Margin for constrastive loss.
margin = 1 # Margin for contrastive loss.
```

---
Expand Down Expand Up @@ -348,34 +348,34 @@ siamese = keras.Model(inputs=[input_1, input_2], outputs=output_layer)
```

---
## Define the constrastive Loss
## Define the contrastive Loss


```python

def loss(margin=1):
"""Provides 'constrastive_loss' an enclosing scope with variable 'margin'.
"""Provides 'contrastive_loss' an enclosing scope with variable 'margin'.
Arguments:
margin: Integer, defines the baseline for distance for which pairs
should be classified as dissimilar. - (default is 1).
Returns:
'constrastive_loss' function with data ('margin') attached.
'contrastive_loss' function with data ('margin') attached.
"""

# Contrastive loss = mean( (1-true_value) * square(prediction) +
# true_value * square( max(margin-prediction, 0) ))
def contrastive_loss(y_true, y_pred):
"""Calculates the constrastive loss.
"""Calculates the contrastive loss.
Arguments:
y_true: List of labels, each label is of type float32.
y_pred: List of predictions of same length as of y_true,
each label is of type float32.
Returns:
A tensor containing constrastive loss as floating point value.
A tensor containing contrastive loss as floating point value.
"""

square_pred = tf.math.square(y_pred)
Expand Down Expand Up @@ -497,8 +497,8 @@ def plt_metric(history, metric, title, has_valid=True):
# Plot the accuracy
plt_metric(history=history.history, metric="accuracy", title="Model accuracy")

# Plot the constrastive loss
plt_metric(history=history.history, metric="loss", title="Constrastive Loss")
# Plot the contrastive loss
plt_metric(history=history.history, metric="loss", title="Contrastive Loss")
```


Expand Down
16 changes: 8 additions & 8 deletions examples/vision/siamese_contrastive.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

epochs = 10
batch_size = 16
margin = 1 # Margin for constrastive loss.
margin = 1 # Margin for contrastive loss.

"""
## Load the MNIST dataset
Expand Down Expand Up @@ -301,33 +301,33 @@ def euclidean_distance(vects):


"""
## Define the constrastive Loss
## Define the contrastive Loss
"""


def loss(margin=1):
"""Provides 'constrastive_loss' an enclosing scope with variable 'margin'.
"""Provides 'contrastive_loss' an enclosing scope with variable 'margin'.
Arguments:
margin: Integer, defines the baseline for distance for which pairs
should be classified as dissimilar. - (default is 1).
Returns:
'constrastive_loss' function with data ('margin') attached.
'contrastive_loss' function with data ('margin') attached.
"""

# Contrastive loss = mean( (1-true_value) * square(prediction) +
# true_value * square( max(margin-prediction, 0) ))
def contrastive_loss(y_true, y_pred):
"""Calculates the constrastive loss.
"""Calculates the contrastive loss.
Arguments:
y_true: List of labels, each label is of type float32.
y_pred: List of predictions of same length as of y_true,
each label is of type float32.
Returns:
A tensor containing constrastive loss as floating point value.
A tensor containing contrastive loss as floating point value.
"""

square_pred = tf.math.square(y_pred)
Expand Down Expand Up @@ -389,8 +389,8 @@ def plt_metric(history, metric, title, has_valid=True):
# Plot the accuracy
plt_metric(history=history.history, metric="accuracy", title="Model accuracy")

# Plot the constrastive loss
plt_metric(history=history.history, metric="loss", title="Constrastive Loss")
# Plot the contrastive loss
plt_metric(history=history.history, metric="loss", title="Contrastive Loss")

"""
## Evaluate the model
Expand Down

0 comments on commit 3d16268

Please sign in to comment.