Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BrainScript: BS.Constants.Range for a constant tensor containing a range of integers #2121

Closed
vermorel opened this issue Jul 17, 2017 · 4 comments

Comments

@vermorel
Copy link
Contributor

vermorel commented Jul 17, 2017

I am facing a problem where the network needs a mask of 0s and 1s starting with k ones and followed by n-k zeroes, where k is is provided as part of the input sequence, and where n is a constant of the problem.

By introducing a BS.Constants.Range, which takes a single argument, obtaining the mask is straightforward:

R = BS.Constants.Range(n) # 1-dimensional constant tensor containing 0, 1, 2, ... , n-1
Mask = BS.Boolean.If( Greater(R, k), 0, 1) # desired resulting mask

There is a possible work-around with the option initFromFilePath from the ParameterTensor; however, it's quite tedious (one ah-hoc input file to be generated for each n).

What would you suggest to cope with such a situation? What about adding BS.Constants.Range?

Update1: I am wondering if BS.Constants.Range(n) cannot be obtained through arrays. However, arrays seems to be intended for higher-level constructs. It's unclear to me if it's possible to convert a float array into a tensor.

Update2: It seems that the following might work:

Range(count) = Splice( array [0..(count-1)] ( i => Constant{i} ) )

Could someone confirm that it will behave as intended?

@ke1337
Copy link

ke1337 commented Jul 18, 2017

Unfortunately there's no official plan to add new features to BrainScript. This is the main reason why CNTK is switching from BrainScript to Python.

@vermorel
Copy link
Contributor Author

@KeDengMS Thanks a lot for your follow-up. That's really a pity though. Python is a show-stopper from a .NET perspective (see #960). BrainScript is highly manageable from a .NET perspective, and it's an excellent DSL use case.

Can I submit the Range() as a pull request? (as a addition to CNTK.core.bs)

@ke1337
Copy link

ke1337 commented Jul 18, 2017

@vermorel Thanks for offering to add this feature to BrainScript, please send a PR.

BTW, I don't think using BrainScript or Python affects your choices over .NET. You can always train a model with Python and load it into .NET, and even use .NET to generate python code if needed. What we want to deliver is not some ideology, it's just a tool to help people get their job done faster and better. Machine learning is moving at fast pace so should we. In my mind Python has more flexibility and extensibility than BrainScript in a lot of ways, which is essential for data pre/post processing.

@spandantiwari
Copy link
Contributor

PR has merged. Closing this issue now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants