I think you can pass an int or a list of ints to the target_type so that the created Dataset returns the desired target values. In your case you would pass 20 to get the gender attribute.
Once this is done, you could collect the targets for all samples and filter them out using your condition (e.g. only “male” targets). Once this is done you could then compute the indices of all “male” samples and pass them to a Subset to only yield these samples.