fc.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. # Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from __future__ import absolute_import
  15. from __future__ import division
  16. from __future__ import print_function
  17. import paddle
  18. import paddle.nn as nn
  19. class FC(nn.Layer):
  20. def __init__(self, embedding_size, class_num):
  21. super(FC, self).__init__()
  22. self.embedding_size = embedding_size
  23. self.class_num = class_num
  24. weight_attr = paddle.ParamAttr(
  25. initializer=paddle.nn.initializer.XavierNormal())
  26. self.fc = paddle.nn.Linear(
  27. self.embedding_size, self.class_num, weight_attr=weight_attr)
  28. def forward(self, input, label=None):
  29. out = self.fc(input)
  30. return out