Model Pipeline - Output guardrails
This pipeline shows how output guardrails help control and improve the responses of a generative AI model. Guardrails guide the model to produce safe, relevant, and accurate outputs.
Jump into concepts and practice - no test required
This pipeline shows how output guardrails help control and improve the responses of a generative AI model. Guardrails guide the model to produce safe, relevant, and accurate outputs.
Loss
1.2 |*
1.0 | **
0.8 | ***
0.6 | ****
0.4 | *****
--------
Epochs
| Epoch | Loss ↓ | Accuracy ↑ | Observation |
|---|---|---|---|
| 1 | 1.2 | 0.45 | Model starts learning basic language patterns. |
| 2 | 0.9 | 0.6 | Model improves in generating coherent text. |
| 3 | 0.7 | 0.75 | Model begins to produce relevant and safe outputs. |
| 4 | 0.5 | 0.85 | Output guardrails help reduce unsafe or irrelevant outputs. |
| 5 | 0.4 | 0.9 | Model converges with high-quality, safe outputs. |
blocked_words = ['badword']
def filter_output(text):
for word in blocked_words:
if word in text:
return 'Content blocked due to policy.'
return text
print(filter_output('This is a badword example.'))def limit_length(text, max_len=10):
if len(text) > max_len:
return text[:max_len]
else:
return text
print(limit_length('Hello, world!'))