forked from microsoft/CNTK
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CNTK v2 library: Sequence to sequence python example
- Loading branch information
Showing
4 changed files
with
228 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
# Copyright (c) Microsoft. All rights reserved. | ||
# Licensed under the MIT license. See LICENSE.md file in the project root | ||
# for full license information. | ||
# ============================================================================== | ||
|
||
import numpy as np | ||
from ...utils import sanitize_input, sanitize_shape, get_data_type | ||
|
||
################################################################################ | ||
# sequence ops | ||
################################################################################ | ||
def is_first(operand, name = ''): | ||
''' | ||
TBA | ||
Example: | ||
TBA | ||
Args: | ||
operand: the symbolic tensor operand denoting a sequence | ||
name (str): the name of the node in the network | ||
Returns: | ||
:class:`cntk.Function` | ||
''' | ||
from cntk import is_first | ||
operand = sanitize_input(operand, get_data_type(operand)) | ||
return is_first(operand, name).output() | ||
|
||
def is_last(operand, name = ''): | ||
''' | ||
TBA | ||
Example: | ||
TBA | ||
Args: | ||
operand: the symbolic tensor operand denoting a sequence | ||
name (str): the name of the node in the network | ||
Returns: | ||
:class:`cntk.Function` | ||
''' | ||
from cntk import is_last | ||
operand = sanitize_input(operand, get_data_type(operand)) | ||
return is_last(operand, name).output() | ||
|
||
def first(operand, name = ''): | ||
''' | ||
TBA | ||
Example: | ||
TBA | ||
Args: | ||
operand: the symbolic tensor operand denoting a sequence | ||
name (str): the name of the node in the network | ||
Returns: | ||
:class:`cntk.Function` | ||
''' | ||
from cntk import first | ||
operand = sanitize_input(operand, get_data_type(operand)) | ||
return first(operand, name).output() | ||
|
||
def last(operand, name = ''): | ||
''' | ||
TBA | ||
Example: | ||
TBA | ||
Args: | ||
operand: the symbolic tensor operand denoting a sequence | ||
name (str): the name of the node in the network | ||
Returns: | ||
:class:`cntk.Function` | ||
''' | ||
from cntk import last | ||
operand = sanitize_input(operand, get_data_type(operand)) | ||
return last(operand, name).output() | ||
|
||
def where(condition, name = ''): | ||
''' | ||
TBA | ||
Example: | ||
TBA | ||
Args: | ||
condition: the symbolic tensor operand denoting a boolean condition flag for each step of a sequence | ||
name (str): the name of the node in the network | ||
Returns: | ||
:class:`cntk.Function` | ||
''' | ||
from cntk import where | ||
condition = sanitize_input(condition, get_data_type(condition)) | ||
return where(condition, name).output() | ||
|
||
def gather(operand, condition, name = ''): | ||
''' | ||
TBA | ||
Example: | ||
TBA | ||
Args: | ||
operand: the symbolic tensor operand denoting a sequence | ||
condition: the symbolic tensor operand denoting a boolean condition flag for each step of a sequence | ||
name (str): the name of the node in the network | ||
Returns: | ||
:class:`cntk.Function` | ||
''' | ||
from cntk import gather | ||
operand = sanitize_input(operand, get_data_type(operand)) | ||
condition = sanitize_input(condition, get_data_type(condition)) | ||
return gather(operand, condition, name).output() | ||
|
||
def scatter(operand, condition, name = ''): | ||
''' | ||
TBA | ||
Example: | ||
TBA | ||
Args: | ||
operand: the symbolic tensor operand denoting a sequence | ||
condition: the symbolic tensor operand denoting a boolean condition flag for each step of a sequence | ||
name (str): the name of the node in the network | ||
Returns: | ||
:class:`cntk.Function` | ||
''' | ||
from cntk import scatter | ||
operand = sanitize_input(operand, get_data_type(operand)) | ||
condition = sanitize_input(condition, get_data_type(condition)) | ||
return scatter(operand, condition, name).output() | ||
|
||
def broadcast_as(operand, broadcast_as_operand, name = ''): | ||
''' | ||
TBA | ||
Example: | ||
TBA | ||
Args: | ||
operand: the symbolic tensor operand denoting a tensor | ||
broadcast_as_operand: the symbolic tensor operand denoting a sequence per whose layout the main operand id to be broadcast | ||
name (str): the name of the node in the network | ||
Returns: | ||
:class:`cntk.Function` | ||
''' | ||
from cntk import broadcast_as | ||
operand = sanitize_input(operand, get_data_type(operand)) | ||
broadcast_as_operand = sanitize_input(broadcast_as_operand, get_data_type(broadcast_as_operand)) | ||
return broadcast_as(operand, broadcast_as_operand, name).output() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.