<jupyter_start><jupyter_text>介绍了pytorch中的激活函数 pytorch的常用激活函数均封装在nn.functional模块中<jupyter_code>import torch
import torch.nn.functional as F
import matplotlib.pyplot as plt
import warnings
warnings.filterwarnings('ignore')
%matplotlib inline
x = torch.linspace(-5, 5, 200)
x_np = x.numpy()
y_relu = F.relu(x).numpy()   # relu
y_tanh = F.tanh(x).numpy()   # tanh
y_sigmoid = F.sigmoid(x).numpy()   # sigmoid
y_softplus = F.softplus(x).numpy()   # softplus
plt.figure(1, figsize=(12,8))
plt.subplot(221)
plt.plot(x_np, y_relu, c='red', label='relu')
plt.ylim((-1, 5))
plt.legend(loc='best')

plt.subplot(222)
plt.plot(x_np, y_sigmoid, c='red', label='sigmoid')
plt.ylim((-0.2, 1.2))
plt.legend(loc='best')

plt.subplot(223)
plt.plot(x_np, y_tanh, c='red', label='tanh')
plt.ylim((-1.2, 1.2))
plt.legend(loc='best')

plt.subplot(224)
plt.plot(x_np, y_softplus, c='red', label='softplus')
plt.ylim((-0.2, 6))
plt.legend(loc='best')

plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.19751809720785937, 'fraction_numerical': 0.03516028955532575, 'mean_word_length': 6.223880597014926, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '339107', 'license': 'MIT', 'n_tokens_mistral': 495, 'n_tokens_neox': 469, 'n_words': 69, 'path': 'Pytorch_demos/basic_tutorail/1.3 activation_function.ipynb', 'repo_name': 'guofei1989/DL_Wiglet', 'size': '967'}