-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Add Text to Spaces #2908
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
Add Text to Spaces #2908
Conversation
Thanks for your PR, are there any particular environments that we wish to use this space with? I can tell before you run the CI that the pre-commit section will fail. |
The idea is kinda interesting, but this feels like something that should start out with a discussion that would guide the implementation, instead of dropping a PR and then we have to simultaneously judge the idea and the implementation. So before even approaching a code review, can you do a proper pitch of this idea? With the motivation, example uses, and the proposed structure. |
Sure, @RedTachyon. I was hoping the In use, one thing that concerns me is the from gym.spaces import Text, Box
from gym import Env
import numpy as np
import random
class PickAndLift(Env):
VERBS = ["lift", "pick", "raise", "grasp"]
COLORS = ["red", "orange", "yellow", "green", "blue", "purple", "pink", "white", "black"]
def __init__(self):
self.observation_space = Text(f"{verb} the {color} block")
self.action_space = Box(low = -np.inf, high = np.inf, shape = (7,), dtype = np.float32)
def reset(self) -> str:
verb = random.choice(self.VERBS)
color = random.choice(self.COLORS)
return f"{verb} the {color} block".format(verb = verb, color = color)
... I hope this provides some clarity in terms of the intentions/motivations for adding this text modality to |
I think the motivation behind this is quite sound, though I think there can be some improvements before this gets merged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some additional minor comments on the code itself
|
||
def __init__( | ||
self, | ||
max_length: int, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would probably be best if max_length
could be -1
, and that would then bypass the check. This would help if the strings themselves could be arbitrarily long (e.g. if we're passing paragraphs of text for whatever reason), so users won't need to specify an arbitrary upper bound
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't imagine a situation in which a user would genuinely want the sampler to output random combinations of characters between certain length bounds. So, if we constrain sampling to a regular expression, are bounds on the length even necessary at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could remove max_length
and leave it to the regex, but if the regex itself does not have a defined length bound, it could match an infinite pattern, and the length of the sampled string will depend on whichever internal limit the sample algorithm might have.
@andrewtanJS I'm thinking a card game might be a decent choice for a toy environment that could use the |
@andrewtanJS @ryanrudes @RedTachyon What changes still need to be made to this PR for it to be reviewed and merged? |
@pseudo-rnd-thoughts For one, we need to devise and implement a simple toy task that uses the text space. I don't have the time to write this at the moment, perhaps someone else is up to it? |
@pseudo-rnd-thoughts it'll need the environment example, as well as the regex implementation if we go with it. After some thought, I wonder if this might just add unnecessary complexity or assumptions to the space, and we could just use the existing @ryanrudes what are your thoughts on this? Would it be easy to support sampling if we add regex? And ultimately, how would the text space be utilized so that the implemented attributes best support the use cases? |
I agree that adding the regex sampling would certainly overcomplicate things, and possibly for little to no good reason anyways... if we were to aim for an all-encompassing sampling method that would be appropriate for most environments, I couldn't imagine a way to do that without further complicating things. If possible, perhaps the |
The problem that I see with this space, is for almost all games then a |
@pseudo-rnd-thoughts that sounds like a good direction to take things. This space should sufficient for general use, and if there's more feature requests that arise we can continue to iterate on it further. |
Description
This adds text spaces to Gym.
Type of change
Checklist:
pre-commit
checks withpre-commit run --all-files
(seeCONTRIBUTING.md
instructions to set it up)