March 19th, 2010 — ideas, mind Tagged ai, empathy, friendly ai
A draft post/idea from the archives that I thought it was about time that I release. Funnily, this was entirely before I started working on NetEmpathy – maybe it’s not as disconnected as I thought from AGI after all!
It is my belief that empathy is a a prerequisite to consciousness.
I recently read Hofstadter’s I am a strange loop, whose central themes are around recursive representations of self leading to our perception of consciousness. For some, the idea that our consciousness is somewhat of an illusion might be hard to swallow – but then, quite likely, so are all the other qualia. They seem real to us, because our mind makes it real. To me, it’s not a huge hurdle to believe. I find the idea that our minds are infinitely representing themselves via self-reflection kind of beautiful in simplicity. You can get some very strange things happening when things start self-reflecting.
For example, Gödel’s incompleteness theorem originally broke Principia Mathematica and can do the same for any sufficiently expressive formal system when you force that formal system to reason about itself. One day I’ll commit to explaining this in a post, but people write entire books about the idea to make Godel’s theorem and it’s consequences easy to understand!
And as an example of self-reflection and recursion being beautiful, I merely have to point to fractals which exhibit self-similarity at arbitrary levels of recursion. Or perhaps the recursive and repeating hallucinations induced by psychedelics give us some clue about the recursive structures within the brain.
Hofstadter also later in the book delves into slightly murky mystical waters, which I find quite entertaining and not without merit. He says that, due to us modelling of the behaviour of others, we also start representing their consciousness too. The eventual conclusion, which is explained in much greater and philosophical detail in his book, is that our “consciousness” isn’t just the sum of what’s in our head but is a holistic total of ourselves and everyone’s representation of us in their heads.
I don’t think the Turing test will really be complete until a machine can model humans as individual and make insightful comments on their motivations. Ok, so that wouldn’t formally be the Turing test any more, but I think that as a judgement of conscious intelligence, the artificial agent needs to at least be able to reflect the motivations of others and understand the representation of itself within others. Lots of recursive representations!
The development of consciousness within AI via empathy is what, in my opinion, will allow us to create friendly AI. Formal proofs won’t work due to computational irreducibility of complex systems. In an admittedly strained analogy this is similar to trying to formally prove where a toy sailboat will end up after dropping it in a river upstream. Trying to prove that it won’t get caught in an eddy before it reaches the ocean of friendliness (or perhaps if you’re pessimistic and you view the eddy as the small space of possibilities for friendly AI). Sure computers and silicon act deterministically (for the most part), but any useful intelligence will interact with an uncertain universe. It will also have to model humans out of necessity as humans are one of the primary agents on the Earth that will need to interact with… perhaps not if it becomes all-powerful but certainly initially. By modelling humans, it’s effectively empathising with our motivations and causing parts of our consciousness to be represented inside it[1].
Given that machine could increase it’s computationally capacity exponentially via Moore’s law (not to mention via potentially large investment and subsequently rapid datacenter expansion) it could eventually model many more individuals than any one human does. So if the AI had a large number of simulated human minds, which would, if accurately modelled, probably bawk at killing the original, then any actions the AI performed would likely benefit the largest number of individuals.
Or perhaps the AI would become neurotic trying to satisfy the desires and wants of conflicting opinions.
In some ways this is similar to Eliezer’s Collected Extrapolated Volition (as I remember it at least… It was a long time ago that I read it. I should do so again to see how/if it fits with what I’ve said here).
[1] People might claim that this won’t be an issue because digital minds designed from scratch will be able to box up individual representations to prevent a bleed through of beliefs. Unfortunately, I don’t think this is a tractable design for AI, even if it was desirable. AI is about efficiency of computation and representation, so these concepts and beliefs will blend. Besides, conceptual blending is quite likely a strong source of new ideas and hypotheses in the human brain.
A draft post/idea from the archives that I thought it was about time that I release. Funnily, this was entirely before I started working on NetEmpathy - maybe it's not as disconnected as I thought from AGI after all!
It is my belief that empathy is a a prerequisite to consciousness.
I recently read Hofstadter's I am a strange loop, whose central themes are around recursive representations of self leading to our perception of consciousness. For some, the idea that our consciousness is somewhat of an illusion might be hard to swallow - but then, quite likely, so are all the other qualia. They seem real to us, because our mind makes it real. To me, it's not a huge hurdle to believe. I find the idea that our minds are infinitely representing themselves via self-reflection kind of beautiful in simplicity. You can get some very strange things happening when things start self-reflecting.
For example, Gödel's incompleteness theorem originally broke Principia Mathematica and can do the same for any sufficiently expressive formal system when you force that formal system to reason about itself. One day I'll commit to explaining this in a post, but people write entire books about the idea to make Godel's theorem and it's consequences easy to understand!
And as an example of self-reflection and recursion being beautiful, I merely have to point to fractals which exhibit self-similarity at arbitrary levels of recursion. Or perhaps the recursive and repeating hallucinations induced by psychedelics give us some clue about the recursive structures within the brain.
Hofstadter also later in the book delves into slightly murky mystical waters, which I find quite entertaining and not without merit. He says that, due to us modelling of the behaviour of others, we also start representing their consciousness too. The eventual conclusion, which is explained in much greater and philosophical detail in his book, is that our "consciousness" isn't just the sum of what's in our head but is a holistic total of ourselves and everyone's representation of us in their heads.
I don't think the Turing test will really be complete until a machine can model humans as individual and make insightful comments on their motivations. Ok, so that wouldn't formally be the Turing test any more, but I think that as a judgement of conscious intelligence, the artificial agent needs to at least be able to reflect the motivations of others and understand the representation of itself within others. Lots of recursive representations!
The development of consciousness within AI via empathy is what, in my opinion, will allow us to create friendly AI. Formal proofs won't work due to computational irreducibility of complex systems. In an admittedly strained analogy this is similar to trying to formally prove where a toy sailboat will end up after dropping it in a river upstream. Trying to prove that it won't get caught in an eddy before it reaches the ocean of friendliness (or perhaps if you're pessimistic and you view the eddy as the small space of possibilities for friendly AI). Sure computers and silicon act deterministically (for the most part), but any useful intelligence will interact with an uncertain universe. It will also have to model humans out of necessity as humans are one of the primary agents on the Earth that will need to interact with... perhaps not if it becomes all-powerful but certainly initially. By modelling humans, it's effectively empathising with our motivations and causing parts of our consciousness to be represented inside it[1].
Given that machine could increase it's computationally capacity exponentially via Moore's law (not to mention via potentially large investment and subsequently rapid datacenter expansion) it could eventually model many more individuals than any one human does. So if the AI had a large number of simulated human minds, which would, if accurately modelled, probably bawk at killing the original, then any actions the AI performed would likely benefit the largest number of individuals.
Or perhaps the AI would become neurotic trying to satisfy the desires and wants of conflicting opinions.
In some ways this is similar to Eliezer's Collected Extrapolated Volition (as I remember it at least... It was a long time ago that I read it. I should do so again to see how/if it fits with what I've said here).
[1] People might claim that this won't be an issue because digital minds designed from scratch will be able to box up individual representations to prevent a bleed through of beliefs. Unfortunately, I don't think this is a tractable design for AI, even if it was desirable. AI is about efficiency of computation and representation, so these concepts and beliefs will blend. Besides, conceptual blending is quite likely a strong source of new ideas and hypotheses in the human brain.
January 21st, 2010 — work Tagged ai, opencog
The 2nd International Conference on Advanced Intelligence 2010 has just released it’s call for papers, which you can download here: ICAI2010 Call For Papers.
How is “Advanced Intelligence” different from general AI? The release says:
Typical features of Advanced Intelligence include: (1) Close interaction and coordination between Natural Intelligence and Artificial Intelligence, (2) Ideas and applications that push the frontiers of both Artificial Intelligence and Natural Intelligence, (3) Large-scale Distributed Intelligence and Web Intelligence
FWIW, I’m not sure I agree with the name, since “advanced” is a relative term, and the field of AGI (artificial general intelligence) is already fragmented enough without adding additional labels. Having said that, I’ve been invited to be an assistant co-chair, so I cordially invite you to submit interesting papers since then they’ll be a greater chance of me getting interesting papers to review
The 2nd International Conference on Advanced Intelligence 2010 has just released it's call for papers, which you can download here: ICAI2010 Call For Papers.
How is "Advanced Intelligence" different from general AI? The release says:
Typical features of Advanced Intelligence include: (1) Close interaction and coordination between Natural Intelligence and Artificial Intelligence, (2) Ideas and applications that push the frontiers of both Artificial Intelligence and Natural Intelligence, (3) Large-scale Distributed Intelligence and Web Intelligence
FWIW, I'm not sure I agree with the name, since "advanced" is a relative term, and the field of AGI (artificial general intelligence) is already fragmented enough without adding additional labels. Having said that, I've been invited to be an assistant co-chair, so I cordially invite you to submit interesting papers since then they'll be a greater chance of me getting interesting papers to review ;-)
January 13th, 2010 — geek Tagged python, s3
January 9th, 2010 — geek Tagged linux
Recently I found out about SizeUp in OSX and found it really useful. Basically it gives you hot keys for window positions, such that you can maximise them vertically and attach them to the left or right of the screen. Great for placing terminal windows and browsers. This is similar to the behaviour in Windows 7 (don’t know what they call it or care, they are just copying this stuff from existing window managers and getting all the credit). You can also send a window to a corner, or maximise horizontally and attach to top/bottom.
I knew it must be possible in linux somehow. For one thing, there’s wmctrl, a command line program for scripting window positions and I found some scripts made by others in the Ubuntu forums that act similar to the way I wanted.
However, it turns out there is something already available if you’re using Compiz as your display manager.
To change to using Compiz and get the required config tool, run:
sudo aptitude install compizconfig-settings-manager compiz-fusion-plugins-extra
And then open the menu System → Preferences → Appearance. Go to the Visual Effects tab and choose “Extra”.
Then fire up the CompizConfig Settings Manager that’s also under System → Preferences. When the dialog loads, go to the filter and type “grid”. This is the module of Compiz that gives you almost the same behaviour as SizeUp (you can get the rest of the behaviour using other modules in the “Window Management” category.
Update: changed the apt-get command to also install compiz-fusion-plugins-extra as the grid plugin is no longer part of the core package.
Recently I found out about SizeUp in OSX and found it really useful. Basically it gives you hot keys for window positions, such that you can maximise them vertically and attach them to the left or right of the screen. Great for placing terminal windows and browsers. This is similar to the behaviour in Windows 7 (don't know what they call it or care, they are just copying this stuff from existing window managers and getting all the credit). You can also send a window to a corner, or maximise horizontally and attach to top/bottom.
I knew it must be possible in linux somehow. For one thing, there's wmctrl, a command line program for scripting window positions and I found some scripts made by others in the Ubuntu forums that act similar to the way I wanted.
However, it turns out there is something already available if you're using Compiz as your display manager.
To change to using Compiz and get the required config tool, run:
sudo aptitude install compizconfig-settings-manager compiz-fusion-plugins-extra
And then open the menu System → Preferences → Appearance. Go to the Visual Effects tab and choose "Extra".
Then fire up the CompizConfig Settings Manager that's also under System → Preferences. When the dialog loads, go to the filter and type "grid". This is the module of Compiz that gives you almost the same behaviour as SizeUp (you can get the rest of the behaviour using other modules in the "Window Management" category.
Update: changed the apt-get command to also install compiz-fusion-plugins-extra as the grid plugin is no longer part of the core package.
January 5th, 2010 — life Tagged kickboxing, opencog
December 26th, 2009 — mind, opencog
Recently I’ve been contemplating a number of potential directions for creating a start-up based on application of OpenCog to a problem or field.
One evening, I had an interesting discussion in bed with my partner that was related to licensing such technology. OpenCog is open source, which is my personal preference for the development of AGI, even if the jury on whether it’s beneficial or needless reckless is still out. As open source software, it means that if we sold expert systems based on OpenCog to end-users, we’d have to also provide the source. Even though we can license it under different terms from SIAI, this isn’t entirely needed since my current viewpoint is that the real value will be in data within the system.
As an analogy, the biological design for the brain isn’t what makes us unique or what encompasses our knowledge and experience of the world. The pattern that’s formed during our childhood and education is what is really valuable, otherwise we’d make no distinction between twins and not particularly care if one twin passed away.
So, the digital mind’s pattern would be the important part that we’d license or sell. However dealing with a dynamic system makes that interesting, since the pattern that was sold/licensed would inevitably change. Learning software could well have the valuable part (the “identity” if you will) morph and change beyond the original deployment. In fact, the software could learn new things which makes the individual deployment “smarter” than the original or any other deployment.
In that case, who owns those improvements? Should we get
the rights, since it was our software that altered itself, or does it belong to the license-holder since the AI learnt the improvement in their environment?
I’m sure with sufficiently rigorous legal-work one could protect towards one view over another, but I’m more interested in what seems right.
Recently I've been contemplating a number of potential directions for creating a start-up based on application of OpenCog to a problem or field.
One evening, I had an interesting discussion in bed with my partner that was related to licensing such technology. OpenCog is open source, which is my personal preference for the development of AGI, even if the jury on whether it's beneficial or needless reckless is still out. As open source software, it means that if we sold expert systems based on OpenCog to end-users, we'd have to also provide the source. Even though we can license it under different terms from SIAI, this isn't entirely needed since my current viewpoint is that the real value will be in data within the system.
As an analogy, the biological design for the brain isn't what makes us unique or what encompasses our knowledge and experience of the world. The pattern that's formed during our childhood and education is what is really valuable, otherwise we'd make no distinction between twins and not particularly care if one twin passed away.
So, the digital mind's pattern would be the important part that we'd license or sell. However dealing with a dynamic system makes that interesting, since the pattern that was sold/licensed would inevitably change. Learning software could well have the valuable part (the "identity" if you will) morph and change beyond the original deployment. In fact, the software could learn new things which makes the individual deployment "smarter" than the original or any other deployment.
In that case, who owns those improvements? Should we get
the rights, since it was our software that altered itself, or does it belong to the license-holder since the AI learnt the improvement in their environment?
I'm sure with sufficiently rigorous legal-work one could protect towards one view over another, but I'm more interested in what seems right.
December 20th, 2009 — life, mind
It’s Christmas time, and I enjoy getting gifts for people even though I’m not religious. I’ve also been enjoying getting rid of lots of stuff I don’t use/need. This not only makes me feel like I’m clearing out mental space (I have Tyler Durden’s words echoing in my head “The things you own, end up owning you”) but also makes me feel good that other people are getting something that they want/need. Especially since I’m either giving the stuff away or selling it cheaply on TradeMe.
I googled “It’s better to give than receive.” since that’s the quote that’s automatically been ingrained into my psyche. Turns out it’s from the Bible, Acts 20:35 (King James Version):
“I have showed you all things, how that so labouring ye ought to support the weak, and to remember the words of the Lord Jesus, how he said: ‘It is more blessed to give than to receive.’”
(I guess “more blessed” translates to “better” these days.)
Never mind that giving psychologically makes us happier than spending money on ourselves. It also physiologically affects us, by releasing, not only the good old reward molecule Dopamine, but also the love neurotransmitter Oxytocin (unfortunately the mention of oxytocin isn’t in the abstract, but it’s discussed here).
There is another aspect of gift giving I want to mention, which I haven’t got any references for, but is based on my intuition on the mechanics of intelligence. When we give someone a gift, we usually have a reason for it, and when we choose a gift for them we tend to think “Will the person like this?”. The act of that means we have to emulate, model, and predict what they want and by activation it re-enforces their pattern within our mind. Does this inadvertently get us thinking of other aspects of their personality and of what other people might like too? I’ve discussed how part of love is the strong bonding of patterns, one’s self in another mind, their mind emulated in the self. This twinning makes us feel connected to the other person. To me, it makes sense that going through this process while selecting gifts for other people will inevitably make one feel more connected in general. And as mentioned above, the neurotransmitter associated with love is also released during giving.
Maybe this is why the gifting economy of Kiwiburn (and the American equivalent) is such a central part of the festivals and contributes to them being such enjoyable experiences.
“We make a living by what we get, but we make a life by what we give.”
– Winston Churchill
It's Christmas time, and I enjoy getting gifts for people even though I'm not religious. I've also been enjoying getting rid of lots of stuff I don't use/need. This not only makes me feel like I'm clearing out mental space (I have Tyler Durden's words echoing in my head "The things you own, end up owning you") but also makes me feel good that other people are getting something that they want/need. Especially since I'm either giving the stuff away or selling it cheaply on TradeMe.
I googled "It's better to give than receive." since that's the quote that's automatically been ingrained into my psyche. Turns out it's from the Bible, Acts 20:35 (King James Version):
"I have showed you all things, how that so labouring ye ought to support the weak, and to remember the words of the Lord Jesus, how he said: 'It is more blessed to give than to receive.'"
(I guess "more blessed" translates to "better" these days.)
Never mind that giving psychologically makes us happier than spending money on ourselves. It also physiologically affects us, by releasing, not only the good old reward molecule Dopamine, but also the love neurotransmitter Oxytocin (unfortunately the mention of oxytocin isn't in the abstract, but it's discussed here).
There is another aspect of gift giving I want to mention, which I haven't got any references for, but is based on my intuition on the mechanics of intelligence. When we give someone a gift, we usually have a reason for it, and when we choose a gift for them we tend to think "Will the person like this?". The act of that means we have to emulate, model, and predict what they want and by activation it re-enforces their pattern within our mind. Does this inadvertently get us thinking of other aspects of their personality and of what other people might like too? I've discussed how part of love is the strong bonding of patterns, one's self in another mind, their mind emulated in the self. This twinning makes us feel connected to the other person. To me, it makes sense that going through this process while selecting gifts for other people will inevitably make one feel more connected in general. And as mentioned above, the neurotransmitter associated with love is also released during giving.
Maybe this is why the gifting economy of Kiwiburn (and the American equivalent) is such a central part of the festivals and contributes to them being such enjoyable experiences.
"We make a living by what we get, but we make a life by what we give."
-- Winston Churchill
December 16th, 2009 — geek
Amazon S3 is a distributed storage service which I’ve recently been working with. Boto is Python library for working with Amazon Web Services, which S3 is one facet of. This post will demonstrate how to upload a file using boto (a future post will demonstrate who to create the parameters for POST multi-part request that another client can use to upload to S3 without knowing your AWS key id or secret access key).
I will assume you’ve signed up for S3 already, and successfully downloaded and installed boto.
import boto
# Fill these in - you get them when you sign up for S3
AWS_ACCESS_KEY_ID = ''
AWS_SECRET_ACCESS_KEY = ''
bucket_name = AWS_ACCESS_KEY_ID.lower() + '-mah-bucket'
conn = boto.connect_s3(AWS_ACCESS_KEY_ID,
AWS_SECRET_ACCESS_KEY)
If you’ve previously learnt about S3 you’ll know that bucket names need to be unique, so that’s why we’ve used the AWS Key ID as a prefix (as this is your unique id it’s unlikely someone else will be using it as a prefix). We’ve also converted the bucket to lowercase, as DNS is case-insensitive and it’s nice to use vanity domains of the form http://[bucket_name].s3.amazonaws.com/.
We create the connection object with boto.connect_s3() and this object let’s us interact with S3. We now create ourselves a bucket and upload a file:
bucket = conn.create_bucket(bucket_name,
location=s3.connection.Location.DEFAULT)
testfile = "replace this with an actual filename"
print 'Uploading %s to Amazon S3 bucket %s' % \
(testfile, bucket_name)
import sys
def percent_cb(complete, total):
sys.stdout.write('.')
sys.stdout.flush()
from boto.s3.key import Key
k = Key(bucket)
k.key = 'my test file'
k.set_contents_from_filename(testfile,
cb=percent_cb, num_cb=10)
There you have it! The set_contents_from_filename is a particularly nifty method which simplifies all the streaming of data to S3. Amazon’s prototype python S3 library required that the file be loaded into memory. This doesn’t work too well if you are working with large media files.
Oh, and the percent_cb function is a call back that gets called as the upload progresses.
Amazon S3 is a distributed storage service which I've recently been working with. Boto is Python library for working with Amazon Web Services, which S3 is one facet of. This post will demonstrate how to upload a file using boto (a future post will demonstrate who to create the parameters for POST multi-part request that another client can use to upload to S3 without knowing your AWS key id or secret access key).
I will assume you've signed up for S3 already, and successfully downloaded and installed boto.
[cce lang="Python"]
import boto
# Fill these in - you get them when you sign up for S3
AWS_ACCESS_KEY_ID = ''
AWS_SECRET_ACCESS_KEY = ''
bucket_name = AWS_ACCESS_KEY_ID.lower() + '-mah-bucket'
conn = boto.connect_s3(AWS_ACCESS_KEY_ID,
AWS_SECRET_ACCESS_KEY)
[/cce]
If you've previously learnt about S3 you'll know that bucket names need to be unique, so that's why we've used the AWS Key ID as a prefix (as this is your unique id it's unlikely someone else will be using it as a prefix). We've also converted the bucket to lowercase, as DNS is case-insensitive and it's nice to use vanity domains of the form http://[bucket_name].s3.amazonaws.com/.
We create the connection object with boto.connect_s3() and this object let's us interact with S3. We now create ourselves a bucket and upload a file:
[cce lang="Python"]
bucket = conn.create_bucket(bucket_name,
location=s3.connection.Location.DEFAULT)
testfile = "replace this with an actual filename"
print 'Uploading %s to Amazon S3 bucket %s' % \
(testfile, bucket_name)
import sys
def percent_cb(complete, total):
sys.stdout.write('.')
sys.stdout.flush()
from boto.s3.key import Key
k = Key(bucket)
k.key = 'my test file'
k.set_contents_from_filename(testfile,
cb=percent_cb, num_cb=10)
[/cce]
There you have it! The set_contents_from_filename is a particularly nifty method which simplifies all the streaming of data to S3. Amazon's prototype python S3 library required that the file be loaded into memory. This doesn't work too well if you are working with large media files.
Oh, and the percent_cb function is a call back that gets called as the upload progresses.
December 12th, 2009 — geek
I have the code-brain.
Now that I live centrally, I’ve been finding myself more frequently excusing myself for having code-brain. What is code-brain? It’s when I’ve spent a day immersed in hacking code without social interaction… and to get out of this state generally just requires time. Usually if I went anywhere it’d require a drive and enough temporal separation for me to revert to a more sociable state, but now that I live in town, it’s about a 5 minute walk to meet up with people which is not enough time and words come with difficulty.
Given the plasticity of the brain, I sometimes wonder if coding for a living is psychologically stunting for one’s social behaviour. However, I can quickly reject that because many coders I know are very social and I don’t see them having the same difficulty.
I sometimes liken it to a mild form of Aspergers, since when dealing with code, for the most part it’s possible to keep everything you need to know about in front of you and it’s finite. It’s not overwhelming except when you’re thrown into a new project with a large existing code-base. Coming from being immersed in such a controlled environment it’s hard to adapt to being in a room full of people because it’s impossible to predict exactly what everyone else will do.
I don’t want to predict what everyone else will do, that’d make life boring. I just know it personally takes time to adjust between the two environments. If anyone has read or seen anything about this phenomenon then I’d appreciate links/comments – mostly so I can understand how to speed the transition and get more enjoyment from social situations without the painful transition.
Possibly I just need to make the transition more often and it’ll become easier
I have the code-brain.
Now that I live centrally, I’ve been finding myself more frequently excusing myself for having code-brain. What is code-brain? It’s when I’ve spent a day immersed in hacking code without social interaction… and to get out of this state generally just requires time. Usually if I went anywhere it’d require a drive and enough temporal separation for me to revert to a more sociable state, but now that I live in town, it’s about a 5 minute walk to meet up with people which is not enough time and words come with difficulty.
Given the plasticity of the brain, I sometimes wonder if coding for a living is psychologically stunting for one’s social behaviour. However, I can quickly reject that because many coders I know are very social and I don’t see them having the same difficulty.
I sometimes liken it to a mild form of Aspergers, since when dealing with code, for the most part it’s possible to keep everything you need to know about in front of you and it’s finite. It’s not overwhelming except when you’re thrown into a new project with a large existing code-base. Coming from being immersed in such a controlled environment it’s hard to adapt to being in a room full of people because it’s impossible to predict exactly what everyone else will do.
I don’t want to predict what everyone else will do, that’d make life boring. I just know it personally takes time to adjust between the two environments. If anyone has read or seen anything about this phenomenon then I’d appreciate links/comments – mostly so I can understand how to speed the transition and get more enjoyment from social situations without the painful transition.
Possibly I just need to make the transition more often and it’ll become easier ;-)
December 9th, 2009 — geek Tagged python
Here’s a little Python snippet I just made up, but is immensely useful because I couldn’t find an obvious method like filter that applied to dictionaries instead of lists. This code pulls out specific key-value pairs from a dictionary and puts them in a new dictionary.
>>> x={ 'test1':1, 'test2':2, 'test3':3 }
>>> my_keys = ('test1','test2')
>>> y=dict(filter(lambda t: t[0] in my_keys, x.items()))
{'test': 1, 'test2': 2}
Obviously the performance characteristics of this won’t scale, but if you just want a few keys out of a dictionary then you should be fine.
Here's a little Python snippet I just made up, but is immensely useful because I couldn't find an obvious method like filter that applied to dictionaries instead of lists. This code pulls out specific key-value pairs from a dictionary and puts them in a new dictionary.
[cce lang="Python"]
>>> x={ 'test1':1, 'test2':2, 'test3':3 }
>>> my_keys = ('test1','test2')
>>> y=dict(filter(lambda t: t[0] in my_keys, x.items()))
{'test': 1, 'test2': 2}
[/cce]
Obviously the performance characteristics of this won't scale, but if you just want a few keys out of a dictionary then you should be fine.